Chapter 12. Java Collections Framework
The Java Collections Framework is designed to support numerous collections in a hierarchical fashion. It is essentially made up of interfaces, implementations, and algorithms.
The Collection Interface
Collections are objects that group multiple elements and store,
retrieve, and manipulate those elements. The interface Collection
is at the root of the collection hierarchy. Subinterfaces of
Collection
include List,
Queue
, and Set
. Table 12-1 shows these interfaces and whether they are ordered or
allow duplicates. The interface Map
is also included in
the table, as it is part of the framework.
Interface |
Ordered |
Dupes |
Notes |
|
Yes |
Yes |
Positional access. Element insertion control. |
|
Can be |
No (Keys) |
Unique keys. One value mapping max per key. |
|
Yes |
Yes |
Holds elements. Usually FIFO. |
|
Can be |
No |
Uniqueness matters. |
Implementations
Table 12-2 lists commonly used collection type implementations, their interfaces, and whether or not they are ordered, sorted, and/or contain duplicates.
Implementations |
Interface |
Ordered |
Sorted |
Dupes |
Notes |
|
|
Index |
No |
Yes |
Fast resizable array |
|
|
Index |
No |
Yes |
Doubly linked list |
|
|
Index |
No |
Yes |
Legacy, synchronized |
|
|
No |
No |
No |
Key/value pairs |
|
|
No |
No |
No |
Legacy, synchronized |
|
|
Insertion,last ... |
Get Java Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.