Java Collection Framework Hierarchy - 1

Java Collection Framework provides an architecture to store and manipulate the group of objects. Java Collection Framework allows to perform all operations on data such as searching, sorting, insertion, manipulation, and deletion. In this Java Collection Framework series, we will cover the major aspects of the java collection framework.

Java collection framework consists of group of classes and interfaces. The java.util package contains all the classes and interfaces for the java collection framework. Below is the hierarchy of the collection framework, 
Hierarchy of Java Collection Framework
Hierarchy of Java Collections Framework
As we have seen, the blue box mentions the interfaces and the yellow box mentions the classes. The dot direction line is mentioned to implement the interfaces and straight direction line mention to extend the classes and interfaces(Whenever the interface extend another interface).

➤ Iterable interface: 
The iterable interface serves as a base interface in the Java collection framework. It is part of java.lang package. The Iterable interface is used to traverse the elements in the collection one by one. The primary method in the Iterable interface is iterator(), which returns iterator. The iterator provides a way to traverse the elements in the collection one by one.
public interface Iterable<T> {
    Iterator<T> iterator();
}
The iterator() method can be used instead of enhanced for loop to provides more control over the iteration process. The iterator can remove the element in a collection.

Three methods of Iterator are -
  1. hasNext() - Return 'true' if the collection has more elements.
  2. next() - Return the next element in the iteration.
  3. remove() - Remove the elements in a collection. This method can only be call once per next() call.
Iterator() method for iteration
Uses of Iterator method of Iterable Interface


➤ Collection Interface:
In the Java collection framework, a collection is the root interface that represents a group of objects known as elements. It provides basic operations such as adding, removing and searching elements. Sub-interfaces such as List, Set and Queue extend Collection Interface.

➤ List Interface:
List Interface of the Java collection framework defines as an ordered collection of elements. And also allows duplicates. Below are the key behaviors of the List Interface. List interface has been implemented in ArrayList, LinkedList, and Vector class.
  • Order : Elements are maintained as order they were inserted. 
  • Duplicate : List allows the duplicate value in a collection.
  • Positional Access : Element can be inserted, updated, removed, and retrieved by index. The index starts from 0.
  • Search : List can be search the element.
  • Iteration : List supports iterating over elements using iterator and enhanced for loop.
  • Range view : It can make sub-List from a List with the range between two index numbers.
➤ Queue Interface:
Queue interface is designed to hold the elements to give priority to processing. Typically it follows the First In First Out (FIFO). The Queue interface extends the Collection interface. Queue allows the duplicate element. This means it can create multiple instances for the same value. Queue interface has been implemented and extended in the PriorityQueue class and the Deque interface accordingly.

➤ Set Interface:
The Set interface does not allow duplicates. The element must be unique. The Set interface extends the Collection interface. Set interface is implemented in HashSet, LinkedHashSet, and TreeSet classes.


In the next blog, we will learn to use of all classes and interfaces that are extended and implemented the List, Queue, and Set interface to store and manipulate the elements.

Next : Purpose and recommendations to use classes (ArrayList, LinkedList, Vector, Stack) of List interface.

Post a Comment

0 Comments