Open In App
Related Articles

Inbuild Data Structures in Java

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

A data structure is a specific way of storing and organizing data so that it can be used effectively and efficiently. An efficient data structure takes up little memory space and requires as little time as possible to execute the data. Java provides a variety of built-in data structures that are commonly used in Data Structures and Algorithms (DSA) implementations.

Here are some of the most important Built-in Data Structures in Java:

Inbuild Data Structure

Internal Working

Static/Dynamic

ArrayList

Array of Object classes

Dynamic

LinkedList

List and Deque

Dynamic

Stack

Vector class

Dynamic

Queue

LinkedList class

Dynamic

PriorityQueue

Binary Heap

Dynamic

HashSet

HashMap

Dynamic

HashMap

Array of buckets

Dynamic

TreeSet

TreeMap 

Dynamic

TreeMap

Red-black tree

Dynamic

HashTable

Slot/Bucket

Dynamic

LinkedHashSet

HashTable and LinkedList

Dynamic


ArrayList:

  • The backing data structure of ArrayList is an array of Object classes. Internally an ArrayList uses an Object[] Array which is an array of objects.
  • All operation like deleting, adding, and updating the elements happens in this Object[] array.

LinkedList:

  • Java’s LinkedList class is a versatile and commonly used data structure that implements the List and Deque interfaces while extending the AbstractSequentialList

Stack:

  • The Stack class in Java extends the Vector class, which is a dynamic array-like data structure.
  • Common stack operations are supported, such as push, pop, peek, and isEmpty.

Queue:

  • A queue is a First-In-First-Out (FIFO) data structure used to manage elements in a way that the first element added is the first one to be removed.
  • The Queue interface can be implemented using LinkedList or ArrayDeque.

PriorityQueue:

  • A priority queue stores elements with associated priorities, and elements with higher priorities are dequeued first.
  • The ordering can be based on natural ordering or defined using a comparator.
  • It’s typically implemented using a binary heap or another data structure that maintains the priority order.

HashSet:

  • HashSet internally uses HashMap to store it’s elements.
  • Whenever you create a HashSet object, one HashMap object associated with it is also created. 

HashMap:

  • HashMap in Java is basically an array of buckets. where each bucket uses linked list to hold elements.
  • A bucket is a linked list of nodes where each node is an object of class Node<K,V>.

TreeSet:

  • The TreeSet internally uses the TreeMap to store the elements.
  • Whenever we create a TreeSet, The JVM internally creates a TreeMap and perform all the operations on TreeMap.

TreeMap:

  • TreeMap is a red-black tree-based implementation of the Map interface, NavigableMap, and AbstractMap classes.

HashTable:

  • Hash table intrinsically contains a slot/bucket in which the storage of key and value pair.
  • It uses the key’s hash code to discover which bucket the key/value of a set should map.

LinkedHashSet:

  • LinkedHashMap in Java is an implementation that combines HashTable and LinkedList implementation.
  • It implements the Map interface.



Last Updated : 19 Sep, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads