Skip to main content

Collections Framework

The Java Collections Framework defines the standard data-structure interfaces and implementations every Java program depends on. Choosing the right collection — ArrayList vs. LinkedList, HashMap vs. TreeMap — and understanding the contracts of equals, hashCode, and ordering is essential for writing correct, performant code.

What You'll Find Here

Notes are being added. Planned topics:

TopicDescription
Collections HierarchyIterable → Collection → List/Set/Queue; why Map is separate.
ListArrayList (O(1) get) vs. LinkedList (O(1) add/remove at ends).
SetHashSet, LinkedHashSet, TreeSet — duplicates, ordering, performance.
MapHashMap, LinkedHashMap, TreeMap, ConcurrentHashMap — choosing the right map.
Queue & DequeArrayDeque, PriorityQueue, BlockingQueue for task patterns.
Iterators & for-eachIterator protocol, ConcurrentModificationException, enhanced-for loop.
Sorting & OrderingComparable (natural order on the class) vs. Comparator (external order).
Immutable CollectionsList.of, Set.of, Map.of (Java 9+); Collections.unmodifiableList.

Learning Path

  1. Collections Hierarchy — understand the interface tree before picking an implementation.
  2. ListArrayList is the default; understand O-complexity trade-offs vs. LinkedList.
  3. MapHashMap internals (buckets, load factor, Java 8 tree bins) are a classic interview deep-dive.
  4. Set — relies on correct equals/hashCode; review Core APIs first.
  5. Sorting & OrderingComparable vs. Comparator appears in almost every Java interview.
  6. Immutable Collections — factory methods from Java 9+ are the modern best practice.