Collection Hierarchy

 The java.util package consists of all the necessary classes and interfaces for the collection framework. The framework includes an iterable interface, which serves as the root for the collection framework and provides an iterator for traversing the collections. All the collections extend this interface, inheriting its properties and methods. The following figure illustrates the hierarchy of the collection framework.

  1. Iterable Interface: This is the root interface of the collection framework and is extended by the collection interface. All interfaces and classes implement this interface. Its primary functionality is to provide an iterator for collections, which can be either an iterator function or a for-each method.

  2. Collection Interface: This interface contains all the basic methods that every collection has, such as adding, removing, and clearing data. All classes implement these methods, regardless of their implementation style. This interface is critical to the framework and has most of its functionalities.

  3. List Interface: This interface is dedicated to the list type of data, which can store ordered collections of objects. It handles position-specific functions, such as getting or setting an element. The following are the classes that implement the List interface:

  • ArrayList: Provides dynamic arrays in Java, automatically increasing or decreasing in size as needed.
  • LinkedList: Implements the DoublyLinkedList data structure.
  • Vector: Provides dynamic arrays in Java but is a legacy class that is thread-safe. However, ArrayList can replace Vector in a single-threaded environment.
  • Stack: Models and implements the Stack data structure based on the last-in-first-out principle. It inherits from Vector and is thread-safe but not recommended for use in a single-threaded environment. ArrayDeque can replace Stack in such environments.
  1. Queue Interface: This interface maintains the FIFO (First In First Out) order, similar to a real-world queue line, and is dedicated to storing elements where their order matters. It supports additional functions for queue addition and removal, such as poll() to remove an item or offer() to add one. The following classes implement the Queue interface:
  • PriorityQueue: Based on the priority heap, this class processes objects based on priority.
  • LinkedList: Implements the Queue data structure.
  • ArrayDeque: Provides a way to apply resizable-array and allows users to add or remove an element from both sides of the queue.
  1. Deque Interface: This interface extends the Queue interface and allows adding and removing elements from both ends of the queue. It includes additional functions like offerFirst(), offerLast(), pollFirst(), and pollLast(). The following classes implement the Deque interface:
  • LinkedList: Implements the linked list data structure.
  • ArrayDeque: Implements the array data structure.
  1. Set Interface: A set is an unordered collection of objects that cannot store duplicate values. The Set interface is implemented by various classes, such as HashSet, TreeSet, and LinkedHashSet. Since all subclasses implement Set, a Set object can be instantiated with any of these classes. Sets are used when we wish to store only unique objects, avoiding duplication. The following are the classes that implement the Set interface:
  • HashSet: This class is an inherent implementation of the hash table data structure or Hashing, and does not guarantee that the objects will be inserted in the same order.
  • TreeSet: Implements the Self-balancing binary tree like red-black tree to maintain the ordering of elements.
  • LinkedHashSet: This class is similar to HashSet, but it uses a doubly linked list to store the data and retains the ordering of elements.
  1. SortedSet Interface: This interface extends the Set interface and includes extra methods that maintain the ordering of elements. It is used to handle sorted data and is implemented by the TreeSet class.

  2. Map Interface: This data structure supports key-value pairs, unlike a Set, which is just a collection of keys. The Map interface is used to store data

  3. SortedMap Interface: This interface extends the Map interface and maintains the order of the keys in the collection. The classes which implement this interface are TreeMap and ConcurrentSkipListMap.

  4. ConcurrentHashMap: ConcurrentHashMap is a thread-safe implementation of the Map interface. It is designed to provide concurrent access to the collection, without the need for any explicit synchronization. It uses a different approach to locking as compared to the Hashtable and the synchronizedMap. It divides the collection into smaller parts, which are then locked separately, reducing contention and increasing concurrency.


In conclusion, the collection framework in Java provides a powerful set of interfaces and classes that make it easy to manage collections of objects. The framework is designed to be extensible, with each interface building on the functionality of its parent interface. The java.util package contains the core classes and interfaces for the collection framework, and provides a solid foundation for building complex data structures in Java. By understanding the hierarchy of the collection framework and the various interfaces and classes it provides, developers can build efficient and powerful applications that take full advantage of the rich collection of data structures provided by Java.

Previous Post Next Post