Java Reference
In-Depth Information
Each of these data structures provides a way to store and retrieve information in a well-
defined manner. The Iterator interface itself isn't a data structure, but it defines a
means to retrieve successive elements from a data structure. For example, Iterator
defines a method called next() that gets the next element in a data structure that con-
tains multiple elements.
8
Iterator is an expanded and improved version of the Enumeration
interface from early versions of the language. Although
Enumeration is still supported, Iterator has simpler method
names and support for removing items.
NOTE
The BitSet class implements a group of bits, or flags, that can be set and cleared indi-
vidually. This class is useful when you need to keep up with a set of Boolean values; you
simply assign a bit to each value and set or clear it as appropriate.
A flag is a Boolean value that represents one of a group of on/off type states in a
program.
The Vector class is similar to a traditional Java array, except that it can grow as neces-
sary to accommodate new elements and also shrink. Like an array, elements of a Vector
object can be accessed via an index value. The nice thing about using the Vector class is
that you don't have to worry about setting it to a specific size upon creation; it shrinks
and grows automatically as needed.
The Stack class implements a last-in, first-out stack of elements. You can think of a
stack literally as a vertical stack of objects; when you add a new element, it's stacked on
top of the others. When you pull an element off the stack, it comes off the top. That ele-
ment is removed from the stack completely, unlike a structure such as an array, where the
elements are always available.
The Hashtable class implements Dictionary, an abstract class that defines a data struc-
ture for mapping keys to values. This is useful when you want to access data through a
particular key rather than an integer index. Because the Dictionary class is abstract, it
provides only the framework for a key-mapped data structure rather than a specific
implementation.
A key is an identifier used to reference, or look up, a value in a data structure.
An implementation of a key-mapped data structure is provided by the Hashtable class,
which organizes data based on a user-defined key structure. For example, in a ZIP Code
list stored in a hash table, you could store and sort data using each code as a key. The
Search WWH ::




Custom Search