Java Reference
In-Depth Information
Summary
TheCollectionsFrameworkisastandardarchitectureforrepresentingandmanipulating
collections,whicharegroupsofobjectsstoredininstancesofclassesdesignedforthis
purpose.Thisframeworklargelyconsistsofcoreinterfaces,implementationclasses,and
utility classes.
Thecoreinterfacesmakeitpossibletomanipulatecollectionsindependentlyoftheir
implementations.Theyinclude
Iterable
,
Collection
,
List
,
Set
,
SortedSet
,
NavigableSet
,
Queue
,
Deque
,
Map
,
SortedMap
,and
NavigableMap
.
Col-
lection
extends
Iterable
;
List
,
Set
, and
Queue
each extend
Collection
;
SortedSet
extends
Set
;
NavigableSet
extends
SortedSet
;
Deque
extends
Queue
;
SortedMap
extends
Map
; and
NavigableMap
extends
SortedMap
.
The framework's implementation classes include
ArrayList
,
LinkedList
,
TreeSet
,
HashSet
,
LinkedHashSet
,
EnumSet
,
PriorityQueue
,
Ar-
rayDeque
,
TreeMap
,
HashMap
,
LinkedHashMap
,
IdentityHashMap
,
WeakHashMap
,and
EnumMap
.Thenameofeachconcreteclassendsinacoreinter-
face name, identifying the core interface on which it is based.
Theframework's implementation classes alsoinclude theabstract
AbstractCol-
lection
,
AbstractList
,
AbstractSequentialList
,
AbstractSet
,
Ab-
stractQueue
,and
AbstractMap
classes.Theseclassesofferskeletalimplementa-
tions of the core interfaces to facilitate the creation of concrete implementation classes.
The Collections Framework would not be complete without its
Arrays
and
Col-
lections
utility classes. Each class supplies various class methods that implement
useful algorithms in the contexts of arrays and collections.
Before Java 1.2's introduction of the Collections Framework, developers had two
choices where collections were concerned: create their own frameworks, or use the
Vector
,
Enumeration
,
Stack
,
Dictionary
,
Hashtable
,
Properties
,and
BitSet
types, which were introduced by Java 1.0.
The Collections Framework has made
Vector
,
Stack
,
Dictionary
, and
Hashtable
obsolete.Theframework's
Iterator
interfacehaslargelyobsoletedthe
Enumeration
interface.ThePreferencesAPIhasmade
Properties
largelyobsol-
ete. Because
BitSet
is still relevant, this class continues to be improved.
Arrays,theCollectionsFramework,andlegacyclassessuchas
BitSet
aresuitable
fororganizinggroupsofobjects(or,inthecaseof
BitSet
,setsofbitsthatareinter-
pretedasBooleantrue/falsevalues),andyoushouldusethemwhereverpossiblebefore
creating your own collection APIs.