8/18/20092
Collections Framework
•Collection
–Generic container, most of the framework implements this
•List
–stores multiple items in an explicit order (repeated elements allowed) –ArrayList, LinkedList, etc.
•Set
–stores unique items in no particular order –HashSet, SortedSet, etc.
•Map
–stores unordered key-value pairs (like a dictionary; keys are unique) –HashMap, Hastable, TreeMap, etc.Buena práctica: –No exponer tipos de datos usados innecesariamente• E.g., declare Map, instancie un HashMap()
General-Purpose Implementationclasses
The primary implementations of the collection interfaces.•HashSet: Hash table implementation of theSetinterface.
•TreeSet: Red-black tree implementation of theSortedSetinterface.
•ArrayList: Resizable-array implementation of theListinterface.
–(Essentially anunsynchronizedVector.) The best all-aroundimplementation of the List interface.
•LinkedList: Doubly-linked list implementation of theListinterface.
–May provide better performance than the ArrayList implementation ifelements are frequently inserted or deleted within the list. –Useful for queues and double-ended queues (deques).
•HashMap: Hash table implementation of the Map interface.
–(Essentially anunsynchronizedHashtable that supports null keys andvalues.) The best all-around implementation of the Map interface.
•TreeMap: Red-black tree implementation of the SortedMap interface.
Collection Operation
•Collections typically provide these operations:
–add(Object o) –add an object to the collection –remove(Object o) –remove the object –clear() –remove all objects from collection –size() –returns a count of obects in collection
Add a Comment