Java Collections Cheat Sheet

The Java Collections Framework provides a set of ready-made data structures and algorithms for storing and manipulating groups of objects. This cheat sheet covers the core interfaces and when to use each.

List

An ordered collection that allows duplicate elements.

  • ArrayList — resizable array, fast random access, use when reads outnumber inserts/deletes
  • LinkedList — doubly linked list, faster inserts/deletes, slower random access
List<String> names = new ArrayList<>();
names.add("Aman");
names.add("Riya");

Set

A collection that does not allow duplicate elements.

  • HashSet — no guaranteed order, fastest add/remove/lookup
  • LinkedHashSet — maintains insertion order
  • TreeSet — keeps elements sorted
Set<Integer> ids = new HashSet<>();
ids.add(101);
ids.add(102);

Map

Stores key-value pairs; keys are unique.

  • HashMap — no guaranteed order, fastest lookups by key
  • LinkedHashMap — maintains insertion order
  • TreeMap — keeps keys sorted
Map<String, Integer> scores = new HashMap<>();
scores.put("Aman", 90);
scores.put("Riya", 95);

Queue / Deque

  • LinkedList — can be used as a Queue or Deque
  • ArrayDeque — fast double-ended queue, preferred over Stack
  • PriorityQueue — orders elements based on natural ordering or a comparator

Quick Reference Table

  • Need fast random access? → ArrayList
  • Need no duplicates? → HashSet
  • Need key-value pairs? → HashMap
  • Need sorted order? → TreeSet / TreeMap
  • Need FIFO processing? → ArrayDeque as a Queue
Most collection classes in Java are not thread-safe by default — use classes from java.util.concurrent, like ConcurrentHashMap, when working with multiple threads.

Master Java with Uncodemy

Hands-on training, live projects, and placement support in our Java Programming Course.

Explore the Course