Back to the main page

Collections
Arrays are the most basic java data structure, they are fixed in size. Utility methods, such as sorting and searching can be found in the Arrays class.

All other main data structures are based on either Sets, Lists, Queues or Maps. Utility methods for these can be found in the Collections class.

Below we list some of the main implementations that can be found in the java.util package. Additional implementations introduced in J2SE 1.5 found in the java.util.concurrent package are listed here. Use of data structures can be vastly improved through Generics. Notes on Generics are listed here.

The main classes.


Key Interfaces and their main methods
<<Comparator>> compare()
<<Enumeration>> hasMoreElements() nextElement()
<<Iterator>> hasNext() next() remove()
<<ListIterator>> hasPrevious() previous() nextIndex() previousIndex() add() set()
<<Iterable>> iterator()
<<Collection>> add() addAll() clear() remove() removeAll() retainAll() size() toArray()
<<List>> get() set() indexOf() lastIndexOf() sublist() listIterator()
<<Queue>> add() remove() element() offer() poll() peek()
<<Deque>> xxxFirst() and xxxLast() for all methods in <<Queue>> with the exception of element() which has getFirst() and getLast()
<<Set>> * no additional methods, only those inherited from <<Collection>>
<<SortedSet>> comparator() first() last()
<<Map>> get() put() putAll() containsKey() containsValue() remove() entrySet() keySet() values() clear() size()
<<SortedMap>> comparator() firstKey() lastKey()
<<Map.Entry>> getKey() getValue() setValue()
<<RandomAccess>> * a marker interface to indicate fast (generally constant) random access


Further Reading.
Oracle's Collections Tutorial