Brief analysis of common interface and class of Java data structure

  • 2020-07-21 07:37:22
  • OfStack

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

Enumeration (Enumeration)

Bit set (BitSet)

Vector (Vector)

The stack (Stack)

Dictionary (Dictionary)

Hash table (Hashtable)

Attributes (Properties)

These classes are legacy, and a new framework, the Collections framework (Collection), has been introduced in Java2, which we will discuss later.

Enumeration (Enumeration)

Although the enumeration (Enumeration) interface itself is not a data structure, it is widely used in the context of other data structures. The enumeration (The Enumeration) interface defines a way to retrieve contiguous elements from a data structure.

For example, enumerations define a method called nextElement that is used to get the next element of a multi-element data structure.

Bit set (BitSet)

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

This class is useful when dealing with a set of 1 Boolean values. You simply assign 1" bit "to each value and then set or clear the bits appropriately.

Vector (Vector)

Vector (Vector) classes are very similar to traditional arrays, but the size of Vector can vary dynamically as needed.

Like array 1, the elements of the Vector object are also accessible by index.

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

The stack (Stack)

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

You can think of a stack as a vertically distributed stack of objects. When you add a new element, you put the new element on top of the other elements.

When you take an element off the stack, you take one element off the top of the stack. In other words, the last element to be pushed out is the first.

Dictionary (Dictionary)

The dictionary (Dictionary) class is an abstract class that defines a data structure that maps keys to values.

Dictionary should be used when you want to access data via a specific key rather than an integer index.

Because the Dictionary class is abstract, it provides only data structures that map keys to values, not specific implementations.

Hash table (Hashtable)

The Hashtable class provides a means to organize data based on user-defined key structures.

For example, in a hash table of an address list, you can store and sort data by zip code as a key, but by person name.

The exact meaning of a hash table key depends entirely on how the hash table is used and the data it contains.

Properties (Properties)

Properties, inherited from the ES129en.Properties class, 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, the environment variable is retrieved as the return value of the System.getProperties () method.

I hope you found this article helpful


Related articles: