Easy Tutorial
❮ Java Object Wait Java Arraylist Set ❯

Java Data Structures

The Java toolkit provides powerful data structures. The data structures in Java mainly include the following interfaces and classes:

These classes are legacy and a new framework, the Collections framework, was introduced in Java 2, which we will discuss later.


Enumeration

The Enumeration interface, although not a data structure itself, is widely used within the context of other data structures. The Enumeration interface defines a way to retrieve successive elements from a data structure.

For example, Enumeration defines a method called nextElement that is used to get the next element from a data structure that contains multiple elements.

For more information about the Enumeration interface, see Enumeration.


BitSet

The BitSet class implements a group of bits or flags that can be set and cleared individually.

This class is very useful when working with a set of Boolean values; you just assign a bit to each value and manipulate it as appropriate.

For more information about the BitSet class, see BitSet.


Vector

The Vector class is very similar to the traditional array, but its size can dynamically increase as needed.

Like arrays, the elements of a Vector object can be accessed via an index.

The main advantage of using the Vector class is that you do not need to specify the size of the object when creating it; its size will dynamically change as needed.

For more information about the Vector class, see Vector.


Stack

The Stack class implements a last-in-first-out (LIFO) data structure.

You can think of a stack as a vertical stack of objects; when you add a new element, it gets placed on top of the others.

When you retrieve an element from the stack, you get the one on the top. In other words, the last element you put in the stack is the first one to be retrieved.

For more information about the Stack class, see Stack.


Dictionary

The Dictionary class is an abstract class that defines a data structure for mapping keys to values.

When you want to access data through a specific key rather than an integer index, you should use Dictionary.

Since Dictionary is an abstract class, it only provides the data structure for mapping keys to values without specific implementations.

For more information about the Dictionary class, see Dictionary.


Hashtable

The Hashtable class provides a means of organizing data based on user-defined key structures.

For example, in a hashtable for an address list, you could store and sort data based on postal codes as keys, rather than names.

The specific meaning of a hashtable key depends entirely on the context of the hashtable and the data it contains.

For more information about the Hashtable class, see Hashtable.


Properties

Properties is a subclass of Hashtable. The Properties class represents 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 used as the return value of the System.getProperties() method to get environment variables.

For more information about the Properties class, see Properties.

❮ Java Object Wait Java Arraylist Set ❯