📦 Section 4 · 30 questions

Collections

30 interview questions and answers in the Collections section.

Questions in this section

  1. What are the main Collection Framework interfaces
  2. What is the difference between List, Set and Queue
  3. What is the difference between ArrayList and LinkedList
  4. When to use ArrayList vs LinkedList
  5. What is the time complexity of operations in ArrayList
  6. What is the time complexity of operations in LinkedList
  7. What is Vector and how does it differ from ArrayList
  8. What is Stack
  9. What is Queue and what implementations exist
  10. What is Deque
  11. What is the difference between HashSet, LinkedHashSet and TreeSet
  12. How does HashSet work internally
  13. What is TreeSet and how does it work
  14. What is Map and what implementations exist
  15. What is the difference between HashMap, LinkedHashMap and TreeMap
  16. When to use TreeMap
  17. What is WeakHashMap
  18. What is ConcurrentHashMap
  19. How does ConcurrentHashMap ensure thread-safety
  20. What is CopyOnWriteArrayList
  21. When to use synchronized collections
  22. How to get a synchronized collection
  23. What is Collections.unmodifiableList()
  24. How does Collections.unmodifiableList() work internally
  25. What is the difference between Iterator and ListIterator
  26. What are fail-fast and fail-safe iterators
  27. What is ConcurrentModificationException
  28. How to properly remove elements during iteration
  29. What is Comparable and Comparator
  30. What operations does the Collection interface support

Study navigator

A structured compilation of 31 core questions designed to prepare software engineers for Junior 🟢, Middle 🟡, and Senior 🔴 Java technical interviews.


📋 All Questions

# Question Difficulty
1 What are the main Collection Framework interfaces ⭐⭐
2 What is the difference between List, Set and Queue ⭐
3 What is the difference between ArrayList and LinkedList ⭐⭐
4 When to use ArrayList vs LinkedList ⭐⭐
5 What is the time complexity of operations in ArrayList ⭐⭐⭐
6 What is the time complexity of operations in LinkedList ⭐⭐⭐
7 What is Vector and how does it differ from ArrayList ⭐
8 What is Stack ⭐
9 What is Queue and what implementations exist ⭐⭐
10 What is Deque ⭐⭐
11 What is the difference between HashSet, LinkedHashSet and TreeSet ⭐⭐
12 How does HashSet work internally ⭐⭐⭐
13 What is TreeSet and how does it work ⭐⭐
14 What is Map and what implementations exist ⭐⭐
15 What is the difference between HashMap, LinkedHashMap and TreeMap ⭐⭐
16 When to use TreeMap ⭐⭐⭐
17 What is WeakHashMap ⭐⭐⭐
18 What is ConcurrentHashMap ⭐⭐⭐
19 How does ConcurrentHashMap ensure thread-safety ⭐⭐⭐
20 What is CopyOnWriteArrayList ⭐⭐⭐
21 When to use synchronized collections ⭐⭐
22 How to get a synchronized collection ⭐⭐
23 What is Collections.unmodifiableList() ⭐
24 How does Collections.unmodifiableList() work internally ⭐⭐
25 What is the difference between Iterator and ListIterator ⭐⭐
26 What are fail-fast and fail-safe iterators ⭐⭐
27 What is ConcurrentModificationException ⭐⭐
28 How to properly remove elements during iteration ⭐⭐
29 What is Comparable and Comparator ⭐⭐
31 What operations does the Collection interface support ⭐⭐

🗺️ Topic Dependency Map

                    ┌──────────────────────────────────────────┐
                    │   1. Collection Framework Overview       │
                    │   Collection, List, Set, Queue, Map      │
                    └──┬──────────┬──────────┬─────────────────┘
                       │          │          │
            ┌──────────┘          │          └──────────┐
            ▼                     ▼                     ▼
    ┌───────────────┐    ┌───────────────┐    ┌────────────────────┐
    │ LIST (3-10)   │    │ SET (11-13)   │    │ MAP (14-20)        │
    │ 3. ArrayList  │    │ 11. HashSet   │    │ 14. Map overview   │
    │    vs Linked  │    │     vs Linked │    │ 15. HashMap vs     │
    │ 4. When what  │    │     vs Tree   │    │     LinkedHashMap  │
    │ 5-6. Big O    │    │ 12. HashSet   │    │     vs TreeMap     │
    │ 7. Vector     │    │     internals │    │ 16. When TreeMap   │
    │ 8. Stack      │    │ 13. TreeSet   │    │ 17. WeakHashMap    │
    │ 9. Queue      │    │               │    │ 18-19. CHM         │
    │ 10. Deque     │    │               │    │ 20. CopyOnWrite    │
    └───────┬───────┘    └───────┬───────┘    └────────┬───────────┘
            │                    │                     │
            └────────────────────┼─────────────────────┘
                                 ▼
                    ┌──────────────────────────────────────────┐
                    │   THREAD-SAFETY (18-22)                  │
                    │   18-19. ConcurrentHashMap               │
                    │   20. CopyOnWriteArrayList               │
                    │   21-22. synchronized collections        │
                    └──────────────────────────────────────────┘

                    ┌──────────────────────────────────────────┐
                    │   ITERATORS & MUTATION (23-28)           │
                    │   23-24. unmodifiableList                │
                    │   25. Iterator vs ListIterator           │
                    │   26. fail-fast vs fail-safe             │
                    │   27. ConcurrentModificationException    │
                    │   28. Safe removal patterns              │
                    └──────────────────────────────────────────┘

                    ┌──────────────────────────────────────────┐
                    │   COMPARISON & CORE CONTRACTS (29, 31)   │
                    │   29. Comparable vs Comparator           │
                    │   31. Collection Operations              │
                    └──────────────────────────────────────────┘

🟢 Junior Level Track (Fundamentals)

  1. Framework Hierarchy: Q1, Q2, Q31 (Collection, List, Set, Queue, Map contracts).
  2. List Implementations: Q3, Q4 (ArrayList vs LinkedList).
  3. Queue & Legacy Structures: Q7, Q8, Q9, Q10 (Vector, Stack, Queue, Deque, ArrayDeque).
  4. Sets & Maps: Q11, Q13, Q14, Q15 (HashSet, TreeSet, HashMap, TreeMap).
  5. Iteration & Protection: Q23, Q24, Q25 (unmodifiableList, Iterator vs ListIterator).

🟡 Middle Level Track (Internals & Complexities)

  1. Big-O & Algorithmic Limits: Q5, Q6 (ArrayList amortized array growth vs LinkedList traversal).
  2. Hash & Tree Mechanics: Q12, Q17 (HashSet backed by HashMap, WeakHashMap reference purging).
  3. Thread Safety: Q21, Q22 (Synchronized wrappers, lock contention).
  4. Mutation Pitfalls: Q26, Q27, Q28 (modCount, ConcurrentModificationException, removeIf).
  5. Sorting & Contracts: Q29 (Comparable.compareTo vs Comparator.compare, Timsort stability).

🔴 Senior Level Track (Performance, Low Latency & Concurrency)

  1. Hardware Cache Locality & SIMD: Q5, Q6 (System.arraycopy intrinsics, CPU L1/L2 cache prefetching vs pointer chasing).
  2. Lock-Free Concurrency & CAS: Q18, Q19 (ConcurrentHashMap table CAS, bucket synchronization, CounterCells / LongAdder).
  3. Copy-on-Write Memory Models: Q20 (CopyOnWriteArrayList volatile arrays, eventual consistency).
  4. Modern Java Innovations: Java 21 SequencedCollection (SequencedSet, SequencedMap) and unmodifiable collections (List.of(), Set.of()).