Concept
Collections
Average lookup and update are O(1) when hashes spread well. Heavy collisions degrade toward O(n) — interview material covers capacity and load factor in depth.
Where it fits
Packages: Core Java (pkg1core), Data structures (pkg3datastructures), LeetCode (pkg5leetcode), JVM (pkg6jvm)
Learn
Existing chapters for this concept.
- Collections
Average lookup and update are O(1) when hashes spread well. Heavy collisions degrade toward O(n) — interview material covers capacity and load factor in depth.
Open lesson →
See it in code
Existing Java examples.
- core 19 Collections Demo
- List: ordered, indexed, allows duplicates (ArrayList / LinkedList). - Set: no duplicates (HashSet=unordered, LinkedHashSet=insertion, TreeSet=sorted). -…
Open example → - core29HashMapDemo
- Keys are unique; put with an existing key replaces the value. - Lookup uses hashCode (bucket) then equals (match within the bucket). - Mutating a key after…
Open example → - core28ComparatorDemo
- Comparable: built into the class (`compareTo`). One natural ordering. - Comparator: external, multiple orderings, lambdas/method refs. - Use…
Open example → - blind75_LC1TwoSum
One-pass hash map stores value->index; check complement each step. Time O(n), Space O(n)
Open example → - blind75_LC49GroupAnagrams
HashMap keyed by sorted char signature. Time O(n k log k), Space O(nk)
Open example →
Prepare
Existing interview questions.
- Autobox in collections?
Clear naming, small methods, immutability, proper exceptions, tests, and idiomatic APIs.
Open question → - Collections Framework — Interview Questions (120+)
By access pattern: order, uniqueness, sorting, concurrency.
Open question → - Comparable vs Comparator (collections context)?
Natural ordering vs custom/multiple orderings.
Open question → - when to use concurrent collections?
Prefer immutability and high-level concurrency utilities over low-level locks.
Open question → - What is a Stream and how does it differ from a Collection?
A pipeline for processing data; not storage.
Open question → - Collections.sort signature?
Use bounded wildcards on input params (PECS), exact types on outputs.
Open question → - Collections Framework — Interview Questions (120+)
Array of buckets; index from hash; chaining; treeify on heavy collisions.
Open question → - Collections Framework — Interview Questions (120+)
HashMap (not synced, allows null), Hashtable (legacy, fully synced), ConcurrentHashMap (scalable concurrency).
Open question → - Collections Framework — Interview Questions (120+)
Same trade-offs as the Set variants.
Open question → - Collections Framework — Interview Questions (120+)
Capacity = bucket count; load factor = fill threshold (0.75).
Open question →
Java versions
- Sequenced collections (JEP 431)
Java 21. getFirst/getLast/reversed on ordered collections.
Open version note → - Convenience Factory Methods for Collections
Convenience Factory Methods for Collections. List.of, Set.of, and Map.of build immutable collections and reject null elements.
Open version note → - Abortable Mixed Collections for G1
Abortable Mixed Collections for G1. G1 can abort a mixed collection that is taking too long, so a pause is more likely to meet its goal.
Open version note → - Sequenced Collections
Sequenced Collections. SequencedCollection, SequencedSet, and SequencedMap add getFirst, getLast, and reversed to ordered collections.
Open version note →