The interfaces defined by java.util are shown next:
Deque (Added by Java SE 6.) Map
NavigableMap (Added by Java SE 6.) Sor tedSet
NavigableSet (Added by Java SE 6.)
Because of its size, the description of java.util is broken into two chapters. This chapter
examines those members of java.util that are part of the Collections Framework. Chapter 18
discusses its other classes and interfaces.
Collections Over view
The Java Collections Framework standardizes the way in which groups of objects are handled
by your programs. Collections were not part of the original Java release, but were added by
J2SE 1.2. Prior to the Collections Framework, Java provided ad hoc classes such as Dictionary,
Vector, Stack, and Properties to store and manipulate groups of objects. Although these classes
were quite useful, they lacked a central, unifying theme. The way that you used Vector was
different from the way that you used Properties, for example. Also, this early, ad hoc approach
was not designed to be easily extended or adapted. Collections are an answer to these (and
The Collections Framework was designed to meet several goals. First, the framework had
to be high-performance. The implementations for the fundamental collections (dynamic arrays,
linked lists, trees, and hash tables) are highly efficient. You seldom, if ever, need to code one
of these "data engines" manually. Second, the framework had to allow different types of
collections to work in a similar manner and with a high degree of interoperability. Third,
extending and/or adapting a collection had to be easy. Toward this end, the entire Collections
Framework is built upon a set of standard interfaces. Several standard implementations
(such as LinkedList, HashSet, and TreeSet) of these interfaces are provided that you may
use as-is. You may also implement your own collection, if you choose. Various special-purpose
implementations are created for your convenience, and some partial implementations are
provided that make creating your own collection class easier. Finally, mechanisms were added
that allow the integration of standard arrays into the Collections Framework.
Algorithms are another important part of the collection mechanism. Algorithms operate
on collections and are defined as static methods within the Collections class. Thus, they are
available for all collections. Each collection class need not implement its own versions. The
algorithms provide a standard means of manipulating collections.
Another item closely associated with the Collections Framework is the Iterator interface.
An iterator offers a general-purpose, standardized way of accessing the elements within a
collection, one at a time. Thus, an iterator provides a means of enumerating the contents of
a collection. Because each collection implements Iterator, the elements of any collection class
can be accessed through the methods defined by Iterator. Thus, with only small changes,
the code that cycles through a set can also be used to cycle through a list, for example.
Search WWH :