1 / 18

13 Collections Framework

13 Collections Framework. Contents. What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map. Objectives. Define a collection Describe the collections framework Describe the collections hierarchy

lucien
Download Presentation

13 Collections Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 13 Collections Framework

  2. Contents • What is Collection? • Collections Framework • Collections Hierarchy • Collections Implementations • Set • List • Map

  3. Objectives • Define a collection • Describe the collections framework • Describe the collections hierarchy • Demonstrate each collection implementation

  4. What is a Collection? • A Collection (also known as container) is an object that contains a group of objects treated as a single unit. • Any type of objects can be stored, retrieved and manipulated as elements of collections.

  5. Collections Framework • Collections Framework is a unified architecture for managing collections Main Parts of Collections Framework • Interfaces • Core interfaces defining common functionality exhibited by collections • Implementations • Concrete classes of the core interfaces providing data structures • Operations • Methods that perform various operations on collections

  6. Collections FrameworkInterfaces

  7. Collections FrameworkImplementations Note: Hashtable uses a lower-case “t”

  8. Collections FrameworkOperations Basic collection operations: • Check if collection is empty • Check if an object exists in collection. • Retrieve an object from collection • Add object to collection • Remove object from collection • Iterate collection and inspect each object • Each operation has a corresponding method implementation for each collection type

  9. Collections Characteristics • Ordered • Elements are stored and accessed in a specific order • Sorted • Elements are stored and accessed in a sorted order • Indexed • Elements can be accessed using an index • Unique • Collection does not allow duplicates

  10. Iterator • An iterator is an object used to mark a position in a collection of data and to move from item to item within the collection Syntax: Iterator <variable> = <CollectionObject>.iterator();

  11. Collection implements extends extends Set List implements implements HashSet SortedSet implements ArrayList Vector LinkedList LinkedHashSet TreeSet Collections HierarchySet and List

  12. Map extends extends implements SortedMap implements TreeMap Hashtable HashMap LinkedHashMap Collections HierarchyMap

  13. Collection Implementations List : Lists of things (classes that implement List) Set : Unique things (classes that implement Set) Map : Things with a unique ID (classes that implement Map) Next!

  14. “Paul” “Mark” “Luke” “John” “Paul” value index 3 1 4 2 0 List A List cares about the index. ArrayList Vector LinkedList

  15. Set A Set cares about uniqueness, it doesn’t allow duplicates. “John” “Luke” “Paul” “Mark” “Fred” “Peter” HashSet LinkedHashSet TreeSet

  16. Map A Map cares about unique identifiers. “ul” key value “Ma” “Le” “Jn” “Pl” “Paul” “Mark” “Luke” “John” “Paul” Hashtable LinkedHashMap TreeMap HashMap

  17. Class Map Set List Ordered Sorted HashMap X No No Hashtable X No No TreeMap X Sorted By natural order or custom comparison rules LinkedHashMap X By insertion order or last access order No HashSet X No No TreeSet X Sorted By natural order or custom comparison rules LinkedHashSet X By insertion order or last access order No ArrayList X By index No Vector X By index No LinkedList X By index No Collection Classes Summary

  18. Key Points • Collections Framework contains: • Interfaces • Implementations • Operations • A list cares about the index. • A set cares about uniqueness, it does not allow duplicates. • A map cares about unique identifiers.

More Related