Collection is a group of [differently typed] objects. [primitives need wrappers] java.util algorithms of java.util.Collections manipulate the collection. Iterators loop over objects of a collection. similar to C++'s STL (C++: "container", Java: "collection") List of objects. indexed Set of unique objects. can't add duplicates (equals() to determine equality). Map of name/value pairs (key/value pairs) Class name features interface it implements ordered sorted ---------- ------- ---------------------- ------- ------ ArrayList dynamic array List yes no fast iteration slow insert/delete fast random access LinkedList fast insert/delete List yes no good for stack, queue slower iteration HashSet unpredictable iteration Set no no LinkedHashSet ordered by insertion Set yes no (default), or by last access TreeSet ascending order Set yes yes (natural order) HashMap fast insert/delete Map no no LinkedHashMap ordered by insertion Map yes no or last access fast iteration TreeMap Map yes yes (natural order user-defined class needs equals() and hashcode() overridden for HashSet and HashMap. needs a Comparator if sort() or TreeSet or TreeMap *********************** Methods all Lists and Sets: add(object) addAll(collection) remove(object) clear() contains(object) returns boolean isEmpty() size() iterator() returns Iterator toArray() returns array of Object all Lists: add(index,object) insert before index set(index,object) overwrite get(index) returns Object indexOf(object) remove(index) SortedSet (e.g. TreeSet) first() last() LinkedList: suitable as stack (LIFO) and queue (FIFO) addFirst(object) addLast(object) getFirst() getLast() removeFirst() removeLast() Map: put( key object, value object ) remove( key object ) //key and value removed get( key object ) //returns value containsKey( key object ) //boolean entrySet() //returns Set of Map.Entry (see iteration below) **************************** Collections algorithms (static utility methods of Collections class) copy(dest_list1,src_list2) max(collection) returns Object min(collection) returns Object reverse(list) shuffle(list) sort(list) **************************** Iterator Iterator iter = collectionObject.iterator(); while (iter.hasNext()) //not at end of collection iter.next() //returns next object in the collection as Object iter.remove() //removes current object ... Iterator iter = mapCollection.entrySet().iterator(); while ( iter.hasNext() ) { entry = (Map.Entry) iter.next(); entry.getKey() entry.getValue()