Collection Framework in Java – Hierarchy, Need & Advantages

1. Objective

In this Collection Framework in Java tutorial, we are going to learn about collections in Java, how we use the Java collection framework. In addition, we will see what are the needs of Java collection framework and advantages of collection framework in Java. At last, we learn the hierarchy of collection framework in Java and to understand better we discuss some Java collection framework with examples.

So, let’s start Collection Framework in Java.

Collection Framework in Java

Collection Framework in Java – Hierarchy, Need & Advantages

Stay updated with latest technology trends
Join DataFlair on Telegram!!

2. What are Collections in Java?

Java Collection is a gathering of individual articles spoke to as a solitary unit. Java gives collection framework which characterizes a few classes and interfaces to speak to a gathering of articles as a solitary unit.

The Java Collection interface (java.util.Collection) and Map interface (java.util.Map) are two principle root interfaces of Java collection classes.

Do you know What is Garbage Collection in Java?

3. Need for Collection Framework in Java

Before Java collection framework (or before JDK 1.2) was presented, the standard strategies for gathering Java items (or accumulations) were an exhibit or vector or Hashtable. Every one of the three of these accumulations had no normal interface.

For instance, in the event that we need to get to components of cluster, vector or hashtable. All these three have distinctive strategies and linguistic structure and syntax for getting to individuals:

Example –

import java.io.*;
import java.util.*;
class Test
{
    public static void main (String[] args)
    {
        int arr[] = new int[] {1, 2, 3, 4};
        Vector<Integer> v = new Vector();
        Hashtable<Integer, String> h = new Hashtable();
        v.addElement(1);
        v.addElement(2);
        h.put(1,"shadow");
        h.put(2,"1shadow");
        System.out.println(arr[0]);
        System.out.println(v.elementAt(0));
        System.out.println(h.get(1));
    }
}

As should be obvious, none of the collections in Java (Array, Vector or Hashtable) actualizes a standard member interface. Thus, it was extremely troublesome for software engineers to compose calculation that can work for all sort of collections.

Another downside is that the greater part of the ‘Vector’ techniques is final. Along these lines, we can’t broaden ‘Vector’ class to actualize a comparable sort of gathering.

Read about Java Garbage Collection Algorithms in detail

Java engineers chose to think of a typical interface to manage the previously mentioned issues and presented Collection Framework, they presented accumulations in JDK 1.2 and changed the heritage Vector and Hashtable to adjust to the gathering system.

4. Advantages of Java Collection Framework

  1. Consistent API: The API has an essential arrangement of interfaces like Collection, Set, List, or Map. Each one of those classes, (for example, ArrayList, LinkedList, Vector and so on) which actualizes, these interfaces have some normal arrangement of strategies.
  2. Diminishes Programming Exertion: The software engineer requires not to stress over an outline of Collection instead of the can center on its best use in his program.
  3. Expands Program Speed and Quality: Increases execution by giving elite usage of valuable information structures and calculations.

Let’s Explore Difference between Method Overloading vs Overriding in Java

5. Hierarchy of Collection Framework in Java

Collections in Java

Hierarchy of Collection Framework in Java

  • Collection: Root interface with essential techniques like add(), remove(), contains(), isEmpty(), addAll(), … and so forth.
  • Set: Doesn’t permit copies. Illustration executions of a Set interface are HashSet (Hashing based) and TreeSet (adjusted BST based). Note that TreeSet executes SortedSet.
  • Rundown: Can contain copies and components are requested. Case usages are LinkedList (connected rundown based) and ArrayList (dynamic exhibit based)
  • Line: Typically arrange components in FIFO arrange aside from special cases like PriorityQueue.
  • Deque: Elements can be embedded and evacuated at the two closures. Permits both LIFO and FIFO.
  • Guide: Contains Key esteem sets. Doesn’t permit copies. Illustration executions are HashMap and TreeMap. TreeMap actualizes SortedMap.

Read about Interface in Java with Example program

Hierarchy of Collection Framework in Java

Hierarchy of Collection Framework in Java

This was all in Collection Framework in Java Tutorial. Hope you like our explanation.

6. Conclusion

Hence, in this collection framework in the Java tutorial, we studied what collections in Java is. Advantages and need of collection framework in Java. In conclusion, we saw the Hierarchy of collection framework in Java with examples. Furthermore, if you have any query, feel free to ask in a comment box.

Related Topic- Variables in Java

For reference 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google | Facebook

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.