Collections Comparison
Fast recall
Quick revision
Core answer
ArrayList for access, LinkedList for end-ops). Set stores unique elements (HashSet unordered, LinkedHashSet insertion order, TreeSet sorted). Map stores key-value pairs (HashMap unordered, LinkedHashMap ordered, TreeMap sorted by key). Choose by three axes: duplicates vs unique, ordering, and access pattern.Whether you can recall the whole landscape and the time complexity of each implementation
Mixing up which structures are ordered vs sorted, or quoting wrong complexities
Group implementations by Hash (O(1), unordered), Linked (ordered), Tree (sorted, O(log n)) — one mental model across Set and Map
Interview-ready guide
Interview answer
There are three families of collections.
List is an ordered sequence that allows duplicates and lets you access by index — ArrayList is the default, and LinkedList also acts as a deque. Set stores unique elements, no duplicates. Map maps unique keys to values.
The trick that ties everything together is a single pattern that repeats inside both Set and Map. The Hash variant — HashSet and HashMap — is unordered and operates in constant time, so it's the fastest and the default. The Linked variant — LinkedHashSet and LinkedHashMap — preserves insertion order, and LinkedHashMap can also use access order, which is what you use to build an LRU cache.
The Tree variant — TreeSet and TreeMap — keeps everything sorted, with log-n operations, and it supports range queries like headMap and tailMap. So once you understand HashSet versus LinkedHashSet versus TreeSet, you automatically understand the three maps too. To choose, I ask three questions.
First, do I allow duplicates? If yes, List; if no, Set. Do I look things up by a key?
Then Map. Second, does order matter? If insertion order matters, use a Linked variant; if I need sorting, use a Tree variant; otherwise use Hash for speed.
Third, what's my access pattern — random access points to ArrayList, end-heavy points to a deque. That three-question framework, plus the Hash-Linked-Tree pattern, lets me place any collection quickly and quote the right complexity for each.
Collections Comparison
Direct Answer
List keeps order and allows duplicates (ArrayList for access, LinkedList for end-ops). Set stores unique elements (HashSet unordered, LinkedHashSet insertion order, TreeSet sorted). Map stores key-value pairs (HashMap unordered, LinkedHashMap ordered, TreeMap sorted by key). Choose by three axes: duplicates vs unique, ordering, and access pattern.
Common Mistakes & Pitfalls
- Confusing ordered with sorted.
LinkedHashSet/LinkedHashMapkeep insertion order;TreeSet/TreeMapkeep sorted order — these are not the same thing. - Using a
Listwithcontainsfor uniqueness. That is an O(n) scan on every check; a hash set gives expected O(1) membership and rejects duplicates for free. - Quoting wrong complexities.
ArrayList.getis O(1) butLinkedList.get(i)is O(n);HashMapis expected O(1) average whileTreeMapis O(log n). - Defaulting to
TreeMap/TreeSetwhen order does not matter. You pay O(log n) for sorting you never use — reach for the Hash variants first.
Check your understanding
Answer these without looking back at the article.
- When would you choose LinkedList over ArrayList?
- How do you decide between HashMap and TreeMap?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.