Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Java data structure


May 10, 2021 Java


Table of contents


Java data structure

The Java toolkit provides a powerful data structure. The data structure in Java consists of the following interfaces and classes:

  • Enumeration
  • BitSet
  • Vector
  • Stack
  • Dictionary
  • Hashtable
  • Properties

These classes are legacies of tradition, and a new framework, collection framework, has been introduced in Java 2, which we'll discuss later.


Enumeration

Although the Enumeration interface is not a data structure in itself, it is widely used in the context of other data structures. T he Enumeration interface defines a way to get continuous elements back from the data structure.

For example, enumerals define a method called nextElement, which is used to get the next element of a data structure that contains multiple elements.

For more information about enumeration interfaces, see Enumeration.


BitSet

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

This class is useful when working with a set of Boolean values, and you only need to assign one "bit" to each value, and then set or clear the bits appropriately to manipulate the Boolean values.

For more information about this class, see BitSet.


Vector

Vector classes are very similar to traditional arrays, but vector size can vary dynamically as needed.

Like arrays, elements of Vector objects can be accessed through an index.

The main benefit of using the Vector class is that you don't have to specify a size for an object when you create it, and its size changes dynamically as needed.

For more information about this class, see Vector


Stack

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

You can think of a stack as a vertically distributed stack of objects, and when you add a new element, you place the new element at the top of the other elements.

When you take an element from the stack, you take an element from the top of the stack. In other words, the last element into the stack is taken out first.

For more information about this class, see Stack.


Dictionary

A dictionary class is an abstract class that defines the data structure of keys mapped to values.

You should use Dictionary when you want to access data through a specific key instead of an integer index.

Because the Dictionary class is an abstract class, it provides only the data structure of the key map to the value, not a specific implementation.

For more information about this class, see Dictionary.


Hashtable

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

For example, in a hash table of address lists, you can store and sort data by postal code as a key, not by the person's name.

The exact meaning of a hash table key depends entirely on the usage story of the hash table and the data it contains.

For more information about this class, see HashTable.


Properties

The Properties class inherited from Hashtable.Properties represents a persistent set of properties. Each key in the property list and its corresponding value is a string.

The Properties class is used by many Java classes. For example, when you get an environment variable, it is the return value of the System.getProperties() method.

For more information about this class, see Properties.