Java Collections Field Guide

Every collection worth knowing for interviews and everyday Java: what it costs, which problems it solves, and example classes that use it. Start from what you need to do, or browse by family.

I need to…

Click a need to jump to the collection that fits it.

The family map

Interfaces in italics, the classes you actually create underneath. Program to the interface: List<Integer> a = new ArrayList<>(), Deque<Integer> s = new ArrayDeque<>(). Since Java 21 the ordered ones also share getFirst, getLast, removeFirst, reversed (SequencedCollection) and pollFirstEntry (SequencedMap).

Collections

Complexity at a glance

O(1) constant O(log n) logarithmic O(n) linear: avoid in a loop * amortised (occasional resize)

Mistakes that cost interviews