Thursday 3 October 2019

Collection Hierarchy in Java

           A Collection is a group of objects represented as a single unit and which defines several classes and interfaces. Collection framework is very important topic for java interview questions, you can read usage, difference and advantages of all interfaces and classes .

In the current post, we will discuss collection hierarchy.

      All classes and interfaces related to Collection Framework are in java.util package. Collection interface is at the top of class hierarchy of Collection Framework as shown in below diagram.

Below diagram shows the class hierarchy of collection framework.

Collection Hierarchy in Java
Collection Hierarchy in Java

        The Collection Framework is divided into four interfaces(three interfaces inherits Collection interface, but map interface is not inherits Collection interface, this is a separate interface ).

  •  List 
      ArrayList, Vector and LinkedList classes implement this interface. It contains duplicates.

  • Queue
      It handles the special group of objects in which elements are removed only from the head. LinkedList and PriorityQueue classes implement this interface.

  • Set
      HashSet and LinkedHashSet classes implements Set interface and TreeSet class implements SortedSet interface which in turn, is extends Set interface. It doesn't contain duplicates.

  • Map
       This is the one interface in Collection Framework which is not inherited from Collection interface. It handles the group of objects as Key/Value pairs. It is implemented by HashMap and HashTable classes and extended by SortedMap interface which in turn is implemented by TreeMap.

Related Posts:--
1) Collection Interview Questions and Answers in Java
2) How to iterate the TreeMap in reverse order in Java
3) How to Remove duplicates from ArrayList in Java
4) Internal Implementation of TreeMap in Java
5) Internal implementation of ArrayList in Java
6) Internal Implementation of LinkedList in Java

No comments:

Post a Comment