Java Collections Framework Tutorial

Collections in java are used in almost every enterprise application. Java Collections framework consists of interfaces and classes which helps in storing and processing the data efficiently. Java Collections Tutorial will look into each of the classes.

Read Also :  Collections in Java Interview Questions 

Java Collections Interfaces and Classes

  • Collection Interface
  • List Interface

    1. ArrayList Class
    2. LinkedList Class
    3. Vector Class

  • Set Interface

    1. HashSet Class
    2. TreeSet Class
    3. LinkedHashSet Class

  • Map Interface

    1. HashMap Class
    2. TreeMap Class
    3. LinkedHashMap Class
    4. Hashtable Class

  • Queue Interface

    1. Priority Queue Class
    Java.util.Collection hierarchy : Java Collections Framework Tutorial

    What is Java Collections Framework?
    Java Collections are similar to containers that consists of multiple items in a single unit. for e,g. collections of candies, list of names etc. Java Collections framework provides unified architecture for manipulating and representing Collections.

    Benefits of Java Collections Framework
    1. It improves program quality and speed.
    2. Increases the chances of reusability of software.
    3. Decreases programming effort.
    Java Collection Interfaces and Classes

    Collection Interface

    This is the root interfaces of the java collection classes hierarchy.A Collection represents a group of objects known as its elements.There is no direct implementation of Collection interface.It has very useful methods like size(),isEmpty(),contains(),add(),remove(),iterator() etc.

    List Interface

    List interface is an ordered collection meaning you can access the elements of a List in specific order. and by an index too. It can contain duplicate elements.Since List is an interface you need to provide a concrete implementation of the interface in order to use it.

    ArrayList Class

    ArrayList in Java tutorials are as follows:

    ArrayList Basics

    1. ArrayList in Java
    2. Initialize ArrayList
    3. Iterate (Loop) ArrayList
    4. Find Length of ArrayList

    ArrayList Sorting

    1. Sort ArrayList in Ascending Order
    2. Sort ArrayList in Descending Order
    3. Sort ArrayList of Objects using Comparable and Comparator

    ArrayList Add/Remove

    1. Add element to ArrayList
    2. Add element at Particular Index of ArrayList
    3. Append Collection elements to ArrayList
    4. Insert all the Collection elements at the Specified Position in ArrayList
    5. Remove element from Specified Index in ArrayList
    6. Remove specified element from ArrayList

    ArrayList Internal Working

    1. How Add() method works Internally in ArrayList

    ArrayList Conversions

    1. Convert HashSet to ArrayList in java
    2. Convert Array to ArrayList
    3. Convert LinkedList to ArrayList
    4. Convert ArrayList to String Array


    1. ArrayList vs Array
    2. ArrayList vs Vector
    3. ArrayList vs LinkedList
    4. ArrayList vs HashMap
    5. ArrayList vs HashSet
    6. ArrayList vs CopyOnWriteArrayList

    Other Tutorials

    1. Synchronize ArrayList
    2. Serialize ArrayList
    3. How to Reverse ArrayList 

    LinkedList Class

    LinkedList in java tutorials are as follows :

    Vector Class

    Vector  is rarely used in the real world. It implements List interface.It maintains insertion order.It is synchronized that's why it gives poor performance in searching, adding, delete and update of the elements.

    1. Difference between Vector and ArrayList

    Set Interface

    Set interface stores unique elements meaning each element can only exists once in a Set.It is unordered meaning it makes no guarantee about the sequence of elements once you iterate them.Since Set is an interface you need to provide a concrete implementation of the interface in order to use it.

    HashSet Class

    TreeSet Class

    TreeSet in java tutorials are as follows:

    LinkedHashSet Class 

    LinkedHashSet implements Set interface. LinkedHashSet unlike HashSet maintains insertion order i.e elements are placed in the order they are inserted. LinkedHashSet should be preferred if you want a unique collection of objects in an insertion order.

    1. How LinkedHashSet works Internally in Java

    Map Interface

    Map interface represents a mapping between  a key and a value.The Map interface does not belongs to the Collection interface hierarchy, so,  it behaves a bit different from the rest of the collection types.Map is an interface you need to provide a concrete implementation of the interface in order to use it.

    HashMap Class

    HashMap in java tutorials are as follows:

    TreeMap Class

    TreeMap in java tutorials are  as follows:

    LinkedHashMap Class

    LinkedHashMap is a Hashtable and linked list implementation of the Map interface, with predictable iteration order. This class is different from HashMap and TreeMap i.e it maintains the insertion order. HashMap does not maintain any order and TreeMap sort the entries in ascending order of keys.

    1. How LinkedHashMap works Internally in Java

    Hashtable Class

    Hashtable implements hash table which maps keys to values. Any non null object can be used as  a key or as a value.

    1. Hashtable vs HashMap

    Queue Interface

    Queue  is an interface  you need to provide a concrete implementation of the interface in order to use  it. Queue typically but do not necessarily order elements in FIFO(first in first out) manner. Every Queue implementation must specify its ordering properties.

    PriorityQueue Class

    PriorityQueue class is based on a priority heap. The elements of the priority queue are ordered according to their natural ordering. A priority queue relying on natural ordering does not permit insertion of non-comparable objects.

    Other Tutorials in Java Collections

    Comparator vs Comparable
    Fail-fast Iterator vs Fail-safe iterator 

    About The Author

    Subham Mittal has worked in Oracle for 3 years .
    For more java articles ,Click here to Subscribe JavaHungry