Java Collections Framework — Interview
Questions & Answers
1. Basic Concept Questions
1 What is a Collection in Java?
2 Difference between Collection and Collections.
3 Main interfaces in the Java Collections Framework.
4 Difference between List, Set, and Map.
5 Why use Collections instead of arrays?
2. List-related Questions
1 Difference between ArrayList and LinkedList.
2 How does ArrayList grow internally?
3 How to make an ArrayList synchronized?
4 Can we store null elements in ArrayList or LinkedList?
5 Which is faster — ArrayList or LinkedList — and why?
6 Ways to iterate over a list (Iterator, for-each, Stream, etc.).
3. Set-related Questions
1 Difference between HashSet, LinkedHashSet, and TreeSet.
2 How does HashSet internally work?
3 Can HashSet contain duplicate elements?
4 How does TreeSet maintain order?
5 What happens if we insert null in TreeSet?
4. Map-related Questions
1 Difference between HashMap and Hashtable.
2 How does HashMap work internally?
3 What is collision in HashMap, and how is it resolved?
4 Difference between HashMap and LinkedHashMap.
5 What is ConcurrentHashMap and how it differs from HashMap.
6 Can we have null key or value in HashMap or Hashtable?
5. Algorithm & Behavior Questions
1 How does [Link]() work?
2 How to make a collection read-only?
3 Difference between fail-fast and fail-safe iterators.
4 How to synchronize a collection manually?
5 Difference between Iterator and ListIterator.
6 How to remove elements safely while iterating?
6. Coding-based Questions
1 Remove duplicates from a list using Set.
2 Count occurrences of each word in a string using Map.
3 Sort a Map by its values.
4 Convert a HashMap to a TreeMap.
5 Find the first non-repeated character in a string using Map.
6 Handle concurrent modifications in a collection.
7. Conceptual Tricky Questions
1 Why override equals() and hashCode() for custom objects in HashSet/HashMap?
2 What happens if hashCode() returns the same value for two different objects?
3 Difference between Comparable and Comparator.
4 Difference between Enumeration, Iterator, and ListIterator.
5 Can we sort a HashMap? How?