The Java toolkit provides a powerful data structure. The data structure in Java mainly includes the following types of interfaces and classes:
- Enumeration
- BitSet
- Vector (Vector)
- Stack
- Dictionary
- Hashtable
- Properties
These classes are legacy, and a new framework, the Collection, has been introduced in Java 2, which we discuss later.
Enumeration
Although the Enumeration interface itself is not a data structure, it is widely used in the context of other data structures. The Enumeration interface defines a way to retrieve contiguous elements from a data structure.
For example, the enumeration defines a method called nextElement, which is used to get the next element of a multi-element data structure.
For more information on the enumeration interface, see Enumeration .
BitSet
The bit collection class implements a set of bits or flags that can be set and cleared individually.
This class is very useful when dealing with a set of Boolean values. You only need to assign a "bit" to each value, and then set or clear the bits appropriately to operate on Boolean values.
For more information on this class, see BitSet .
Vector (Vector)
Vector classes are very similar to traditional arrays, but the size of a Vector can change dynamically as needed.
Like arrays, elements of a Vector object can also be accessed via an index.
The main advantage of using the Vector class is that you don't have to specify a size for the object when creating it, and its size will change dynamically as needed.
For more information on this class, see Vector
Stack
The Stack implements a LIFO data structure.
You can think of the stack as a vertically-distributed stack of objects. When you add a new element, you place the new element at the top of other elements.
When you fetch an element from the stack, you take an element from the top of the stack. In other words, the last pushed element was first taken out.
For more information on this class, see Stack .
Dictionary
The Dictionary class is an abstract class that defines the data structure that keys map to values.
When you want to access data through a specific key rather than an integer index, you should use a Dictionary at this point.
Since the Dictionary class is an abstract class, it only provides data structures for key mappings to values, and does not provide a specific implementation.
For more information on this class, see the Dictionary .
Hashtable
The Hashtable class provides a means of organizing data based on a user-defined key structure.
For example, in the hash table of the address list, you can store and sort data based on the postal code as a key, rather than by person name.
The exact meaning of the hash table key is entirely dependent on the use case of the hash table and the data it contains.
For more information on this class, see HashTable .
Properties
Properties inherits from the Hashtable.Properties class to represent a persistent set of properties. Each key and its corresponding value in the property list is a string.
The Properties class is used by many Java classes. For example, it is the return value of the System.getProperties() method when it gets an environment variable.
For more information on this class, see Properties .
Comments
Post a Comment