Techoceanhub logo

Collection hierarchy and interfaces (List, Set, Map)

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.

  1. List: The List interface represents an ordered collection of elements that allows duplicates. Some commonly used implementations of the List interface are ArrayList and LinkedList. The List interface extends the Collection interface 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.
  2. Set: The Set interface represents a collection of unique elements with no particular order. It does not allow duplicate elements. Some commonly used implementations of the Set interface are HashSet and TreeSet. The Set interface extends the Collection interface and provides methods for adding, removing, and checking the presence of elements.
  3. Map: The Map interface represents a mapping between keys and values. Each key in a Map must be unique, and it is associated with a corresponding value. Some commonly used implementations of the Map interface are HashMap and TreeMap. The Map interface does not extend the Collection interface, 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.

Share:

Categories

Archives

Related Posts

Array Destructuring

Array Destructuring Array destructuring is a powerful syntax introduced in ES6 that allows you to unpack elements from an array

Read More »

Explore our Affiliated partner links

hostgator website plan

Hostgator

Best Website hosting plans & Best for 24/7 support.

hostinger webhosting plan

Hostinger

Reasonable website hosting packages for small business & 24/7 Email support

Elementor pro

Design Worpdress website quickly using Elementor Builder and AI

buy elementor website templates

Buy Elementor Website Template

Buy ready made Elementor Website Template from us & Get Free Elementor pro licence for 1 year .