Java Reference
In-Depth Information
Beware of some typographic issues. The word
Arrays
(in constant width font) is short for
the class
java.util.Arrays
, but in the normal typeface, the word “arrays” is simply the
plural of “array” (and will be found capitalized at the beginning of a sentence). Also, note
that
HashMap
and
HashSet
follow the rule of having a “midcapital” at each word boundary,
whereas the older
Hashtable
does not (the “t” is not capitalized).
The
java.util
package has become something of a catch-all over the years. Besides the leg-
acy Date/Time API covered in
Interfacing with Legacy Date and Calendar Classes
,
several
other classes from
java.util
are not covered in this chapter. All the classes whose names
begin with
Abstract
are, in fact, abstract, and we discuss their nonabstract subclasses. The
quently than some of the classes discussed here and is simple enough to learn on your own; I
have examples of it in Recipes and .
BitSet
stores the bits very compactly in memory, but
because it predates the Collection API and wasn't retrofitted, it doesn't implement any of the
standard collection interfaces. Also here are
EnumSet
and
EnumMap
, specialized for efficient
storage/retrieval of enums. These are newer than
BitSet
and
do
implement the modern col-
lection interfaces.
We start our discussion of data structuring techniques with one of the oldest structures, the
array. We discuss the overall structure of
java.util
's Collections Framework. Then we'll
go through a variety of structuring techniques using classes from
java.util
.
Using Arrays for Data Structuring
Problem
You need to keep track of a fixed amount of information and retrieve it (usually) sequen-
tially.
Solution
Use an array.