The data structures provided by the Java utility package are very powerful and perform a wide range of functions. These data structures consist of the following interface and classes −
All these classes are now legacy, and a new framework called the Collections Framework has been implemented by Java-2, which is covered in the next chapter. −
The Enumeration interface is not a data structure itself, but within the context of other data structures, it is very relevant. A means of retrieving successive elements from a data structure is described by the Enumeration interface.
Enumeration, for example, describes a method called nextElement that is used in a data structure to get the next element
A group of bits or flags that can be set and cleared individually is enforced by the BitSet class.
In cases where you need to keep up with a collection of Boolean values, this class is very useful; you just assign each value a bit and collection or clear it as necessary.
The Vector class is similar to a standard Java array, except that to accommodate new elements, it can expand as required.
Like an array, a vector object's elements can be accessed via an index to the vector.
The good thing about using the Vector class is that upon development, you don't have to worry about setting it to a particular size; when needed, it shrinks and grows automatically.
The Stack class implements a last-in-first-out (LIFO) stack of elements.
You can think of a stack literally as a vertical stack of objects; when you add a new element, it gets stacked on top of the others.
When you pull an element off the stack, it comes off the top. In other words, the last element you added to the stack is the first one to come back off.
The Dictionary class is an abstract class which defines the structure of the data for mapping values to keys.
In situations where you want to be able to access data through a specific key rather than an integer index, this is beneficial.
Since the Dictionary class is abstract, instead of a particular implementation, it provides only the basis for a key-mapped data structure.
Based on some user-defined main structure, the Hashtable class provides a means of organising data.
For instance, you might save and sort data based on a key such as ZIP code rather than on the name of a person in an address list hash table.
With regard to hash tables, the precise definition of keys is totally dependent on the use of the hash table and the data it contains.
Properties is a Hashtable subset. It is used to preserve lists of values where the key is a string and the value is a string as well.
Many other Java classes use the Properties class. For instance, when obtaining environmental values, it is the type of object returned by System.getProperties().