Language collection paths · 6 steps

Java collections

The five core Java collections in the order you need them, each paired with the structure underneath, a visualizer and a problem that uses it.

Who it is for
Java developers who want to know what the standard collections cost and which one to reach for.
By the end
You can choose between the core Java collections by operation cost and avoid the usual misuse of each.
  1. Step 2: Dynamic array

    The default sequence. ArrayList<Integer> boxes primitives; remove(int index) and remove(Object value) are different overloads.

  2. Step 3: Hash map

    Lookup by key in expected O(1). HashMap.get returns null for a missing key; getOrDefault and merge avoid the extra branch.

  3. Step 4: Hash set

    Membership without values. HashSet.add returns false when the value is already present.

  4. Step 5: Queue and deque

    First in, first out, the order BFS needs. ArrayDeque is the usual stack and queue in modern Java; it rejects null elements.

  5. Step 6: Priority queue

    Repeatedly take the smallest (or largest) item. PriorityQueue is a min-heap by natural order or a Comparator; its iterator is not in sorted order.