Sitemap
Raj Dhok

Raj Dhok

I breath air.

2 min readDec 26, 2025

--

Collection interface in Java

Press enter or click to view image in full size

Collection is a interface in Java Collection framework that represents a group of objects, with specific implementations for ordered, unordered, or key value pair collections.

  1. ArrayList :

ArrayList is like a dynamic array.

Elements are stored in the same order as we enter them.

Index based accessing is allowed.

duplicates are allowed.

ArrayList is family of list it implements list (checkout the digram attached at the end of the blog).

Insertion and deletion of data is difficult.

Time complexity to search an element is O(n).

2. LinkedList :

Nodes will be created and each node will be linked eith each other.

Behind the scene it uses Doubly LinkedList.

Faster insertion and removal of data/nodes as compare to ArrayList.

Belongs to the family of List and Dequeue interface.

Duplicates are allowed.

Order of insertion is preserved.

3. ArrayDeque :

Size is dynamic.

Uses Double ended queue behind the scene.

Insertion and removal will be done from rare and front end.

Duplicates are allowed.

Order of insertion is preserved.

Get Raj Dhok’s stories in your inbox

Join Medium for free to get updates from this writer.

4. Priority Queue :

Belongs to the family of queue.

Index based insertion is not allowed.

Follows MinHeap data structure.

Duplicates are allowed.

Order of insertion is not maintained.

5. TreeSet :

Elements less than the root will be on the left and elements greater than root will be on the right side of the tree.

It forms a balanced binary search tree.

For skewed tree search time complexity is o(n) if not skewed then o(log n).

Solution for skewed trees? HashSet, LinkedHashSet these follow hashing algorithms

6. HashSet :

Duplicates are not allowed.

default capacity 16.

Order of insertion is not maintained.

Belongs to set family.

time complexity O(1) space complexity O(n).

7. LinkedHashSet :

Belonds to HashSet which belongs to set.

No duplicates are allowed.

Hashing is used for insertion and returning values.

Order of insertion is maintained.

Press enter or click to view image in full size

--

--