review the collections provided in the standard Java (1.0 and 1.1) library ( BitSet is not included here since it’s more of a special-purpose class):
review the collections provided in the standard Java (1.0 and 1.1) library (
is not included here since it’s more of a special-purpose class):
associates numerical indices to objects. It holds objects of a known type so
you don’t have to cast the result when you’re looking up an object.
It can be multidimensional, and it can hold primitives. However, its size
cannot be changed once you create it.
also associates numerical indices to objects – you can think of arrays and
as random-access collections. The
automatically resizes itself as you add more elements. But a
can hold only
handles, so it won’t hold primitives and you must always cast the result
when you pull an
handle out of a collection.
is a type of
which is a way to associate, not numbers, but
with other objects. A
also supports random access to objects, in fact, its whole design is focused
around rapid access.
is a last-in, first-out (LIFO) queue.
you’re familiar with data structures, you might wonder why there’s
not a larger set of collections. From a functionality standpoint, do you really
a larger set of collections? With a
you can put things in and find them quickly, and with an
you can iterate through the sequence and perform an operation on every element
in the sequence. That’s a powerful tool, and maybe it should be enough.
no concept of order.
and arrays give you a linear order, but it’s expensive to insert an
element into the middle of either one. In addition, queues, dequeues, priority
queues, and trees are about
the elements, not just putting them in and later finding them or moving through
them linearly. These data structures are also useful, and that’s why they
were included in Standard C++. For this reason, you should consider the
collections in the standard Java library only as a starting point, and, if you
must use Java 1.0 or 1.1, use the JGL when your needs go beyond that.
you can use Java 1.2 you should use only the new collections, which are likely
to satisfy all your needs. Note that the bulk of this book was created using
Java 1.1, so you’ll see that the collections used through the rest of the
book are the ones that are available only in Java 1.1:
This is a somewhat painful restriction at times, but it provides better
backward compatibility with older Java code. If you’re writing new code
in Java 1.2, the new collections will serve you much better.