🗃️ Collections Framework
19 Java concepts, each explained step by step with real code, a common trap and practice questions.
- The collections hierarchyIterable → Collection → List / Set / Queue; Map is separate.
- ArrayListResizable array: fast get, amortized O(1) add, slow middle insert.
- LinkedListDoubly linked list; O(n) get, rarely the right choice.
- List operations & pitfallsremove(int) vs remove(Object), subList views, indexOf.
- HashSet, LinkedHashSet, TreeSetNo order, insertion order, sorted order.
- HashMap, LinkedHashMap, TreeMapKey-value maps and their ordering guarantees.
- How HashMap workshashCode → bucket, equals within bucket, load factor, resize, tree bins.
- Mutable keys & bad hashCodeMutating a key after insertion loses the entry.
- Map API essentialsgetOrDefault, putIfAbsent, computeIfAbsent, merge, entrySet iteration.
- Queue, Deque & ArrayDequeFIFO/LIFO, offer/poll/peek vs add/remove/element.
- PriorityQueueBinary heap ordered by priority; iteration order is not sorted.
- Legacy collectionsVector, Stack, Hashtable — why ArrayDeque and HashMap replaced them.
- Iterator & ConcurrentModificationExceptionFail-fast iterators; removing safely with iterator.remove or removeIf.
- Comparable vs ComparatorNatural ordering vs external ordering; Comparator.comparing().thenComparing().reversed().
- The Collections utility classsort, reverse, shuffle, max, frequency, unmodifiable and synchronized wrappers.
- Immutable collectionsList.of, Set.of, Map.of, copyOf; no nulls; unmodifiable view vs immutable copy.
- Arrays.asList gotchasFixed-size, backed by the array, add() throws UnsupportedOperationException.
- Sequenced collectionsJava 21 getFirst, getLast, reversed() on List, Deque, LinkedHashSet, LinkedHashMap.
- Big-O of collection operationsChoosing the right collection by access pattern.