A collection is a data structure – actually, an object – to hold other objects, which let you store and organize objects in useful ways for efficient access Check out the package! Lots of interfaces and classes providing a general collection framework. Programmers may also provide implementations specific to their own requirements | Collections Lecture 6: Concept A collection is a data structure – actually, an object – to hold other objects, which let you store and organize objects in useful ways for efficient access Check out the package! Lots of interfaces and classes providing a general collection framework. Programmers may also provide implementations specific to their own requirements Overview of the interfaces and concrete classes in the collection framework Collection Set SortedSet List HashSet ArrayList LinkedList TreeSet Map SortedMap WeakHashMap HashMap TreeMap ListIterator Iterator Root interface – Collection (1) Methods working with an individual collection public int size() public boolean isEmpty() public boolean contains(Object elem) public boolean add(Object elem) Depends on whether the collection allows duplicates public boolean remove(Object elem) public boolean equals(Object o) public int hashCode() public Iterator iterator() public Object[] toArray() Returns a new array containing references to all the elements of the collection public Object[] toArray(Object[] dest) What is returned depends on whether the elements in the collection fit in dest If the type of dest is not compatible with the types of all elements in the collection, an exception is thrown Root interface – Collection (2) Primary methods operating in bulk from another collection public boolean containsAll(Collection coll) public boolean addAll(Collection coll) Returns true if any addition succeeds public boolean removeAll(Collection coll) Returns true if any removal succeeds public boolean retainAll(Collection coll) Removes from the collection all elements that are not elements of coll public void clear() Remove all elements from this collection The SDK does NOT provide any direct implementations of the Collection interface Most of the actual collection types implement this interface, usually by implementing an extended interface such as Set or List This interface is typically used to pass . | Collections Lecture 6: Concept A collection is a data structure – actually, an object – to hold other objects, which let you store and organize objects in useful ways for efficient access Check out the package! Lots of interfaces and classes providing a general collection framework. Programmers may also provide implementations specific to their own requirements Overview of the interfaces and concrete classes in the collection framework Collection Set SortedSet List HashSet ArrayList LinkedList TreeSet Map SortedMap WeakHashMap HashMap TreeMap ListIterator Iterator Root interface – Collection (1) Methods working with an individual collection public int size() public boolean isEmpty() public boolean contains(Object elem) public boolean add(Object elem) Depends on whether the collection allows duplicates public boolean remove(Object elem) public boolean equals(Object o) public int hashCode() public Iterator iterator() public Object[] toArray() Returns a new array containing