Collections
The Java
Collections Framework is a set of
important utility classes and interfaces in the
java.util package
for working with collections of objects. The Collections Framework
defines two fundamental types of collections. A
Collection is a group of objects while
a
Map is a set of mappings, or associations, between
objects. A
Set is a type of Collection
with no duplicates, and a
List
is a Collection in which the elements are ordered.
SortedSet
and SortedMap are
specialized sets and maps that maintain their elements in a sorted
order.
Collection
, Set,
List, Map,
SortedSet, and SortedMap are
all interfaces, but the java.util package also
defines various concrete implementations, such as lists based on
arrays and linked lists, and maps and sets based on hashtables or
binary trees. Other important interfaces are
Iterator
and ListIterator,
which allow you to loop through the objects in a collection. The
Collections Framework was added in Java 1.2, but prior to that
release you can use Vector and
Hashtable, which are approximately the same as
ArrayList and HashMap.
In Java 1.4, the Collections API
added the
RandomAccess
marker interface, which is
implemented by List implementations that support
efficient random access (i.e., it is implemented by
ArrayList and Vector but not by
LinkedList). Java 1.4 also introduced
LinkedHashMap
and LinkedHashSet,
which are
hashtable-based
maps and sets that preserve the insertion order of elements. Finally,
IdentityHashMap ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access