O'Reilly logo

Java 7 Pocket Guide, 2nd Edition by Patricia Liguori, Robert Liguori

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. 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 Collection interface is at the root of the collection hierarchy. Subinterfaces of Collection include List, Queue, and Set. Table 15-1 shows these interfaces and whether they are ordered or allow duplicates. The Map interface is also included in the table, as it is part of the framework.

Table 15-1. Common collections

Interface

Ordered

Dupes

Notes

List

Yes

Yes

Positional access; element insertion control

Map

Can be

No (Keys)

Unique keys; one value mapping max per key

Queue

Yes

Yes

Holds elements; usually FIFO

Set

Can be

No

Uniqueness matters

Implementations

Table 15-2 lists commonly used collection type implementations, their interfaces, and whether or not they are ordered, sorted, and/or contain duplicates.

Table 15-2. Collection type implementations

Implementations

Interface

Ordered

Sorted

Dupes

Notes

ArrayList

List

Index

No

Yes

Fast resizable array

LinkedList

List

Index

No

Yes

Doubly linked list

Vector

List

Index

No

Yes

Legacy, synchronized

HashMap

Map

No

No

No

Key/value pairs

Hashtable

Map

No

No

No

Legacy, synchronized

LinkedHashMap

Map

Insertion, last access

No

No

Linked list/hash table

TreeMap

Map

Balanced

Yes

No

Red-black tree map

PriorityQueue

Queue

Priority

Yes

Yes

Heap implementation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required