In Java, the collection hierarchy is a set of interfaces and classes that define different types of collections and their behaviors. The three main interfaces in the collection hierarchy are List, Set, and Map.
- List: The
Listinterface represents an ordered collection of elements that allows duplicates. Some commonly used implementations of theListinterface areArrayListandLinkedList. TheListinterface extends theCollectioninterface and provides additional methods to access and manipulate elements by their index. Elements in a list can be accessed in the order they were inserted. - Set: The
Setinterface represents a collection of unique elements with no particular order. It does not allow duplicate elements. Some commonly used implementations of theSetinterface areHashSetandTreeSet. TheSetinterface extends theCollectioninterface and provides methods for adding, removing, and checking the presence of elements. - Map: The
Mapinterface represents a mapping between keys and values. Each key in aMapmust be unique, and it is associated with a corresponding value. Some commonly used implementations of theMapinterface areHashMapandTreeMap. TheMapinterface does not extend theCollectioninterface, but it provides methods to manipulate the key-value pairs, such as adding, removing, and retrieving values based on their keys.
Here’s a graphical representation of the collection hierarchy in Java:
Collection (Interface)
|
________________________________
| |
List (Interface) Set (Interface)
| |
ArrayList HashSet (Class)
LinkedList TreeSet (Class)
Map (Interface)
|
HashMap (Class)
TreeMap (Class)
In addition to these core interfaces and classes, there are other specialized implementations and interfaces available in the Java Collections Framework, such as Queue, Deque, and SortedSet. These provide additional functionality and behavior for specific use cases.




