Inbuild Data Structures in Java
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:
Array of Object classes
Array of buckets
HashTable and LinkedList
- 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 class is a versatile and commonly used data structure that implements the
Deque interfaces while extending 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.
- 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.
Queue interface can be implemented using
- 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 internally uses HashMap to store it’s elements.
- Whenever you create a HashSet object, one HashMap object associated with it is also created.
- 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>.
- 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 is a red-black tree-based implementation of the Map interface, NavigableMap, and AbstractMap classes.
- 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.
- LinkedHashMap in Java is an implementation that combines HashTable and LinkedList implementation.
- It implements the Map interface.
Share your thoughts in the comments
Please Login to comment...