Collection interfaces - The primary means by
which collections are manipulated.
Collection
- A group of objects. No assumptions are made about the order of
the collection (if any) or whether it can contain duplicate
elements.
Set - The
familiar set abstraction. No duplicate elements permitted. May or
may not be ordered. Extends the Collection interface.
List -
Ordered collection, also known as a sequence. Duplicates are
generally permitted. Allows positional access. Extends the
Collection interface.
Queue - A
collection designed for holding elements before processing.
Besides basic Collection operations, queues provide
additional insertion, extraction, and inspection operations.
Deque - A
double ended queue, supporting element insertion and
removal at both ends. Extends the Queue interface.
Map - A
mapping from keys to values. Each key can map to one
value.
General-purpose implementations - The primary
implementations of the collection interfaces.
HashSet - Hash
table implementation of the Set interface. The best
all-around implementation of the Set interface.
LinkedHashSet
- Hash table and linked list implementation of the Set
interface. An insertion-ordered Set implementation that
runs nearly as fast as HashSet.
ArrayList -
Resizable array implementation of the List interface
(an unsynchronized Vector). The best
all-around implementation of the List interface.
ArrayDeque -
Efficient, resizable array implementation of the Deque
interface.
LinkedList
- Doubly-linked list implementation of the List interface.
Provides better performance than the ArrayList
implementation if elements are frequently inserted or deleted
within the list. Also implements the Deque interface. When
accessed through the Queue interface, LinkedList
acts as a FIFO queue.
HashMap - Hash
table implementation of the Map interface (an
unsynchronized Hashtable that supports null keys
and values). The best all-around implementation of the Map
interface.
LinkedHashMap
- Hash table and linked list implementation of the Map
interface. An insertion-ordered Map implementation that
runs nearly as fast as HashMap. Also useful for building
caches (see
removeEldestEntry(Map.Entry) ).
Legacy implementations - Older collection
classes were retrofitted to implement the collection
interfaces.
Vector -
Synchronized resizable array implementation of the List
interface with additional legacy methods.
Hashtable
- Synchronized hash table implementation of the Map
interface that does not allow null keys or values, plus
additional legacy methods.
Special-purpose implementations
WeakHashMap
- An implementation of the Map interface that stores only
weak
references to its keys. Storing only weak references enables
key-value pairs to be garbage collected when the key is no longer
referenced outside of the WeakHashMap. This class is
the easiest way to use the power of weak references. It is
useful for implementing registry-like data structures, where the
utility of an entry vanishes when its key is no longer reachable by
any thread.
Abstract implementations - Skeletal
implementations of the collection interfaces to facilitate custom
implementations.
AbstractCollection
- Skeletal Collection implementation that is neither a set
nor a list (such as a "bag" or multiset).
Algorithms - The Collections
class contains these useful static methods.
sort(List)
- Sorts a list using a merge sort algorithm, which provides
average case performance comparable to a high quality quicksort,
guaranteed O(n*log n) performance (unlike quicksort), and
stability (unlike quicksort). A stable sort is one that
does not reorder equal elements.
Iterators - Similar to the familiar Enumeration
interface, but more powerful, and with improved method names.
Iterator
- In addition to the functionality of the Enumeration
interface, enables the user to remove elements from the backing
collection with well-defined, useful semantics.
ListIterator
- Iterator for use with lists. In addition to the functionality of
the Iterator interface, supports bidirectional iteration,
element replacement, element insertion, and index retrieval.
Ordering
Comparable
- Imparts a natural ordering to classes that implement it.
The natural ordering can be used to sort a list or maintain order
in a sorted set or map. Many classes were retrofitted to
implement this interface.
Comparator
- Represents an order relation, which can be used to sort a list or
maintain order in a sorted set or map. Can override a type's
natural ordering or order objects of a type that does not
implement the Comparable interface.
ConcurrentModificationException - Thrown by iterators
and list iterators if the backing collection is changed
unexpectedly while the iteration is in progress. Also thrown by
sublist views of lists if the backing list is changed
unexpectedly.
Performance
RandomAccess
- Marker interface that lets List implementations
indicate that they support fast (generally constant time) random
access. This lets generic algorithms change their behavior to
provide good performance when applied to either random or
sequential access lists.
Array Utilities
Arrays -
Contains static methods to sort, search, compare, hash, copy,
resize, convert to String, and fill arrays of primitives
and objects.