Collection Framework and key interfaces

//Collection Framework and key interfaces
In this tutorial I have explained each collection interface and it's features. This tutorial is overview of collection Interfaces and hierarchical representation of collection framework interfaces and implementation classes . For better understanding of Collection Framework also see Collections Framework Introduction

The Key Interfaces of Collection Framework

Collection Framework provides many interfaces, in this tutorial I am going to explain the major Interfaces and these are key Interfaces of Collection Framework. They are:

  1. Collection
  2. List
  3. Set
  4. SortedSet
  5. NavigableSet
  6. Queue
  7. Map
  8. SortedMap
  9. NavigableMap

The below image illustrates the key interfaces of Collection Framework and its Implementation classes hierarchy.

1. Collection Interface :

  1. The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements.
  2. The JDK does not provide any direct implementations of this interface: The implementation splitted to its child interfaces and their implementation classes.
  3. Collection interface provides the most common general methods which are applicable for any collection object (List, Set, Queue implementations).

2. List Interface :

  1. An ordered collection (also known as a sequence).
  2. Insertion order preserved, if user used List type implementation, user has control over the order, because the insertion order and retrieval order of an element is same.
  3. If List type implementations used Duplicate elements allowed to insert.

3. Set Interface :

  1. Insertion order not preserved, if user used Set type implementation, user has no control over the order, because the insertion order and retrieval order of an element is not same.
  2. If Set type implementations used Duplicate elements not allowed to insert.

4. SortedSet Interface :

  1. Child interface of Set. It is a set that holds the elements in natural sorting (Ascending) order.
  2. The element which we are adding to a SortedSet implementation that element should implements Comparable Interface. Because when we are adding element, it uses Comparable implementation to sort the order. ( Just remember this Interface Comparable, I will explain more in depth details about Comparator and sorting order in further tutorials).

5. NavigableSet Interface :

  1. It is a set that extends SortedSet, it means it is child Interface of SortedSet.
  2. It provides navigational methods. For example if you want to retrieve an element that higher than or less than a given value. If you want such kind of navigation, NavigableSet provides navigational utility methods.

6. Queue Interface :

  1. A collection designed for holding elements prior to processing.
  2. A queue supports the insert and remove operations using a FIFO (First-In-First-Out) manner.
  3. Queue provides prior to processing methods.

7. Map Interface :

  1. An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
  2. Map represent each element as key value pair, and that key value pair called Entry.
  3. Map interface provides the most common methods that is applicable for any Map implementation type object.

8. SortedMap Interface :

  1. Child interface of Map. It is a map that holds the key elements in natural sorting (Ascending) order.
  2. The key element which we are adding to a SortedMap implementation that element should implements Comparable Interface. Because when we are adding element, it uses Comparable implementation to sort the order. ( Just remember this Interface Comparable, I will explain more in depth details about Comparator and sorting order in further tutorials).

9. NavigableMap Interface :

  1. It is a Map that extends SortedMap, it means it is child Interface of SortedMap.
  2. It provides navigational methods. For example if you want to retrieve a key element that higher than or less than a given key. If you want such kind of navigation, NavigableMap provides navigational utility methods.
Next further tutorials I will explain about methods of each interface and its implementation classes through examples and use cases.

2 Comments

  1. priya April 11, 2018 at 5:16 am - Reply

    The Java Collections Framework provides useful and robust algorithms such as searching and sorting on collections, and the interoperability between collections and arrays. Thanks for sharing this.

Leave A Comment