Java Reference
In-Depth Information
•
HashSet<E>
A
Set
implemented as a hashtable. A good, general-
purpose implementation for which searching, adding, and remov-
ing are mostly insensitive to the size of the contents.
•
TReeSet<E>
A
SortedSet
implemented as a balanced binary tree.
Slower to search or modify than a
HashSet
, but keeps the elements
sorted.
•
ArrayList<E>
A
List
implemented using a resizable array. It is ex-
pensive to add or delete an element near the beginning if the list
is large, but relatively cheap to create and fast for random ac-
cess.
•
LinkedList<E>
A doubly linked
List
and
Queue
implementation.
Modification is cheap at any size, but random access is slow.
•
HashMap<K,V>
A hashtable implementation of
Map
. A very generally
useful collection with relatively cheap lookup and insertion times.
•
treeMap<K,V>
An implementation of
SortedMap
as a balanced binary
tree to keep its elements ordered by key. Useful for ordered data
sets that require moderately quick lookup by key.
•
WeakHashMap<K,V>
An hashtable implementation of
Map
that referen-
useful only in limited situations.
Nearly all the implementation classes in
java.util
are both
Cloneable
and
Serializable
. The exceptions are
PriorityQueue
which is not
Cloneable
,
and
WeakHashMap
which is neither.
In this chapter you first learn about iteration because it is useful with all
the collection classes. We then cover ordering since it is used by many
of the collection types. We then present the details of the
Collection
-
based types, followed by the
Map
-based types. After that we look at the
various utilities available, and we show you how to make unmodifiable
and type-safe versions of your collections. Next we show you the syn-
chronized and concurrent collections. You will then learn how to write
your own iteration and collection types in case you have a need that the