JavaCollections Framework Overview

Collections Framework Overview

The Java Collections Framework is a unified architecture of interfaces and classes for storing, retrieving, and manipulating groups of objects. Instead of every project reinventing lists, sets, and maps from scratch, Java ships one consistent, well-tested set of building blocks that every codebase can rely on.

The Core Interface Hierarchy
At the top sits the Collection interface, representing any group of objects. Three major families branch off it, each with a different contract about order and duplicates. Map is deliberately kept separate — it stores key-value pairs, not a plain collection of elements, so it does not extend Collection at all.

Interface

Ordered?

Duplicates?

Common Implementations

List

Yes (index-based)

Allowed

ArrayList, LinkedList

Set

Depends on implementation

Not allowed

HashSet, TreeSet

Queue / Deque

Yes (insertion/priority order)

Usually allowed

ArrayDeque, PriorityQueue

Map (separate hierarchy)

Depends on implementation

Keys unique, values may repeat

HashMap, TreeMap

List preserves insertion order and lets you access elements by numeric index. Set forbids duplicate elements. Queue and its sub-interface Deque model ordered processing, like a line at a checkout counter. Each of these interfaces is covered in depth on its own dedicated page.
Code to the Interface, Not the Implementation

A foundational habit in idiomatic Java is declaring variables using the interface type, and only mentioning the concrete class once — on the right-hand side, where the object is actually created.

Coding to the interface

Java
import java.util.List;
import java.util.ArrayList;

public class InterfaceStyleDemo {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>(); // declared as List, not ArrayList
        names.add("Ada");
        names.add("Grace");
        System.out.println(names);
    }
}
Tip
Declaring List<String> names instead of ArrayList<String> names means the rest of your code never depends on which specific implementation you picked. If you later discover LinkedList or an immutable list fits better, you change one line — new ArrayList<>() — and nothing else needs to change, because every method that only uses List methods keeps working unmodified.
Generics Keep Collections Type-Safe
The angle-bracket type parameter, like the String in List<String>, tells the compiler exactly what type of element the collection may hold. Attempting to add the wrong type is caught at compile time rather than surfacing as a runtime ClassCastException later. The dedicated Generics page covers this type-safety mechanism — and how to write your own generic classes and methods — in full.
  • Collection is the root interface for groups of individual elements

  • List, Set, and Queue each add a different ordering/duplicate contract

  • Map is a separate key-value hierarchy, not a Collection

  • Always prefer declaring variables by interface type over concrete class

  • Generics give every collection compile-time type safety

Note
Every implementation covered later in this section — ArrayList, LinkedList, HashSet, TreeSet, HashMap, and more — is judged by the same set of trade-offs: how fast is lookup, how fast is insertion, does it preserve order, and does it allow duplicates. Keep that lens in mind as you move through the rest of the Collections Framework.