A Collection is a group of objects represented as a single unit. The Java Collection Framework provides several interfaces and classes to store and manipulate groups of objects efficiently.
The Java Collection Framework is divided into four main interfaces. Three of them—
The Collection Framework is one of the most important topics for Java interviews. You should understand the usage, differences, and advantages of its various interfaces and classes.
In this post, we will discuss the Collection Framework hierarchy.
All the classes and interfaces related to the Java Collection Framework are available in the java.util package. The Collection interface is the root interface of the Collection Framework hierarchy, as shown in the diagram below.
The following diagram illustrates the class hierarchy of the Java Collection Framework.
![]() |
| Collection Hierarchy in Java |
The Java Collection Framework is divided into four main interfaces. Three of them—
List, Set, and Queue—extend the Collection interface, whereas the Map interface does not extend the Collection interface. Instead, it is a separate interface in the Java Collections Framework.- List
List interface is implemented by the ArrayList, Vector, and LinkedList classes. It allows duplicate elements and preserves the insertion order of elements.- Queue
Queue interface represents a collection of elements that are typically processed in a First-In, First-Out (FIFO) order. In a queue, elements are generally added at the tail and removed from the head. The LinkedList and PriorityQueue classes implement the Queue interface.- Set
HashSet and LinkedHashSet classes implement the Set interface, while the TreeSet class implements the SortedSet interface, which in turn extends the Set interface. A Set does not allow duplicate elements.- Map
Map interface is the only interface in the Java Collections Framework that does not extend the Collection interface. It stores data as key-value pairs, where each key is unique and maps to a corresponding value. The HashMap and Hashtable classes implement the Map interface, while the TreeMap class implements the SortedMap interface, which in turn extends the Map interface.Summary
-
Collectionis the root interface for collections of individual objects. -
Liststores ordered elements and allows duplicates. -
Setstores unique elements. -
Queueis used for processing elements, typically in FIFO order. -
Mapstores key-value pairs and is independent of theCollectioninterface. - The framework provides multiple implementations, each optimized for different use cases, making it easier to choose the right data structure for your application.

No comments:
Post a Comment