Java · OOP, JVM and backend craft
Give an overview of the Java collections framework.
Short answer
The collections framework is built around List, Set, Map, Queue and Deque interfaces. Pick an implementation based on ordering, access pattern, mutability and concurrency needs.
The core interfaces describe behaviour, and implementations provide the data structure. Code against the interface so the implementation can change later. The most common choices are ArrayList, HashSet, HashMap and ArrayDeque.
The main families
- List: ordered, index-based, duplicates allowed. ArrayList, LinkedList
- Set: no duplicate elements. HashSet, LinkedHashSet, TreeSet
- Map: key to value, unique keys. HashMap, LinkedHashMap, TreeMap
- Queue and Deque: FIFO and double-ended operations. ArrayDeque, PriorityQueue
- Concurrent variants such as ConcurrentHashMap and CopyOnWriteArrayList
Map<String, Integer> counts = new HashMap<>();
for (String word : words) {
counts.merge(word, 1, Integer::sum);
}Ordering is often the deciding factor. HashSet makes no ordering promise. LinkedHashSet preserves insertion order. TreeSet and TreeMap keep sorted order using Comparable or a Comparator. ArrayDeque is usually a better queue than LinkedList.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Which collection preserves insertion order?
- 2When would you use a TreeMap instead of a HashMap?
- 3What does fail-fast iteration mean?
- 4Which collections are safe for concurrent use?
Say it in the interview
I start from the interface I need: List for ordered index access, Set for uniqueness, Map for key-value lookup, and Queue or Deque for FIFO work. Then I choose an implementation based on ordering and concurrency. ArrayList, HashMap and ArrayDeque cover most cases. I code against interfaces, and I remember that the standard collections are not thread-safe unless I choose a concurrent variant.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Java mock interview and get scored feedback on depth, clarity and confidence.