World 13 of 26 · Intermediate

🗃️ Collections Framework

19 Java concepts, each explained step by step with real code, a common trap and practice questions.

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