Explain the Java Collections Framework: the main interfaces and when to use List, Set and Map implementations.
ReportedSource: GeeksforGeeks interview experience: Wipro Software Engineer
List (ArrayList/LinkedList), Set (HashSet/LinkedHashSet/TreeSet), Queue/Deque (ArrayDeque/PriorityQueue) and Map (HashMap/LinkedHashMap/TreeMap); pick by ordering, duplicates and access pattern; concurrent variants for threads.
Core interfaces. Collection -> List (ordered, duplicates allowed), Set (no duplicates), Queue/Deque; and separately Map (key-value pairs).
Common implementations.
- List:
ArrayList(fast random access, default choice),LinkedList(cheap inserts at ends, also a Deque). - Set:
HashSet(O(1) average, no order),LinkedHashSet(insertion order),TreeSet(sorted, O(log n)). - Map:
HashMap(O(1) average),LinkedHashMap(insertion/access order, LRU caches),TreeMap(sorted keys, range queries). - Queue/Deque:
ArrayDeque(stack or queue),PriorityQueue(heap ordering). - Concurrent:
ConcurrentHashMap,CopyOnWriteArrayList,BlockingQueueimplementations.
Utilities. Collections.sort, unmodifiableList, List.of(...) immutable factories, Streams API for filtering/mapping.
Interview follow-ups. How HashMap works (hashing, buckets, resize at load factor 0.75, tree bins), equals/hashCode contract, Comparable vs Comparator, fail-fast iterators and ConcurrentModificationException.