Java Collection Framework Tutorial with Examples

Java Collection framework tutorial with examples will help you understand how to use the collection classes in an easier way. A collection in Java is an object that stores a group of objects as a single unit. Java collection framework provides several interfaces and classes to help group the objects as a unit.

The Java collection framework has two main interfaces, the Collection interface, and the Map interface. Several other classes and interfaces implement and extend these two main interfaces to make the collection framework.

Here is the pictorial representation of the Java Collection Framework hierarchy.

(click image to open it in a new window)

Java Collection Framework Cheat Sheet

As you can see from the above collection framework hierarchy, the Collection interface and Map interface are at the top of the hierarchy.

Collection Interface

The Collection interface is the root interface and provides common methods like add, remove, clear, contains, equals, hashcode, and iterator.

List interface

The List interface extends the Collections interface. The List represents index based ordered collection of the objects. The elements contained in the List are ordered and can be inserted, accessed or searched based on their index. The list may contain duplicate elements. The main classes implementing the List interface are ArrayList and LinkedList.

Set interface

The Set interface extends the Collection interface and represents a collection that does not contain any duplicate elements (it can only have one null element as well). The main classes implementing the Set interface are TreeSet, HashSet and LinkedHashSet.

Queue Interface

The Queue interface extends Collection interface and represents a collection that is usually ordered by FIFO (first in first out) order. The main classes implementing the Set interface are LinkedList, ArrayDeque and PriorityQueue.

Map Interface

The map interface is a root interface and allows storing the key value pairs. The map does not allow duplicate keys. Map interface does not guarantee the order of the elements, however, some implementations like TreeMap does. The main classes implementing the Set interface are Hashtable, HashMap, TreeMap and LinkedHashMap.

Utility Classes

In addition to the above mentioned main interfaces and classes, there are two utility classes that are part of the Java collection framework.

Java Collections and Arrays Utility classes

1. Collections class

The Collections class contains static utility methods that either accepts or returns the collection. The collection class provides many useful methods for shuffling, reversing, sorting and searching collection objects.

2. Arrays Class

Similar to the Collections class, the Arrays class contains static utility methods for manipulating arrays. The Arrays class provides many useful methods for sorting, searching, copying and filling the arrays.

Java Collection Examples

List Examples

ArrayList Examples

LinkedList Examples

Comparable Examples

Comparator Examples

HashMap Examples

LinkedHashMap Examples

HashSet Examples

LinkedHashSet Examples

Iterator Examples

ListIterator Examples

TreeMap Examples

TreeSet Examples

Arrays Examples

Vector Examples

Java Collection interface Javadoc
Java Map interface Javadoc

Please let me know if you liked the Java Collection framework tutorial with examples in the comments section below.

About the author



My name is RahimV and I have over 16 years of experience in designing and developing Java applications. Over the years I have worked with many fortune 500 companies as an eCommerce Architect. My goal is to provide high quality but simple to understand Java tutorials and examples for free. If you like my website, follow me on Facebook and Twitter.


  • Hello!
    In test Java Object Oriented Programming Quiz 4 I find mistake:
    In question
    What will happen when you compile and run the following code?

    abstract class One{
    public One(){

    abstract void nothing();

    public class Test{
    public static void main(String[] args) {
    One one = new One();
    the given correct answer is
    None of the above,
    since in explanation is written
    The code will give compilation error “Cannot instantiate the type One”.

    So, maybe, correct answer is Compilation error&

    • Hello Paul,

      You are absolutely right. It was my mistake. The given explanation is right that the code will give compilation error, but the option number was wrong. As you said, the correct option is 3.
      I’ve now fixed it.

      Thanks a lot for your time in correcting my mistake.


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

Online Shopping