Java Reference
In-Depth Information
C H A P T E R 5
Collecting Objects
Applicationsoftenmustmanagecollectionsofobjects.Althoughyoucanusearraysfor
this purpose, they are not always a good choice. For example, arrays have fixed sizes,
makingittrickytodetermineanoptimalsizewhenyouneedtostoreavariablenumber
ofobjects.Also,arrayscanbeindexedbyintegersonly,whichmakethemunsuitablefor
mapping arbitrary objects to other objects.
Java's standard class library provides the Collections Framework and legacy APIs to
managecollectionsonbehalfofapplications.
Chapter5
firstpresentsthisframework,and
then introduces you to these legacy APIs (in case you encounter them in legacy code).
BecausetheframeworkandlegacyAPIsmaynotsatisfyspecificneeds,thischapterlastly
focuses on creating special-purpose collections APIs.
Note
Java's concurrency utilities (discussed in
Chapter 6
) extend the Collections
Framework.
The Collections Framework
The
Collections Framework
isastandardarchitectureforrepresentingandmanipulating
collections, which are groups of objects stored in instances of classes designed for this
purpose.Afterpresentinganoverviewofthisframework'sarchitecture,thissectionintro-
ducesyoutothevarioustypes(mainlylocatedinthe
java.util
package)thatcontrib-
ute to this architecture.
Architecture Overview
The Collection Framework's architecture is divided into three sections:
•
Core interfaces
: The framework provides core interfaces for manipulating col-
lections independently of their implementations.