23 June 2021

#Collections

#Collections

Key Concepts


Topic Sub-Topics (comma separated) Basic Intermediate Advanced Expert
Collections Framework Collection Interface, Map Interface, Iterator, Iterable
Core Interfaces List, Set, Queue, Deque, Map, SortedMap, NavigableMap
List Implementations ArrayList, LinkedList, Vector, Stack
Set Implementations HashSet, LinkedHashSet, TreeSet
Queue Implementations PriorityQueue, ArrayDeque, BlockingQueue
Map Implementations HashMap, LinkedHashMap, TreeMap, Hashtable, ConcurrentHashMap
Legacy Collections Enumeration, Vector, Hashtable, Properties
Iteration Techniques Iterator, ListIterator, For-Each, Stream Iteration
Utility Classes Collections Class, Arrays Class, Comparator, Comparable
Sorting & Searching Comparable, Comparator, Collections.sort(), Binary Search
Synchronization Synchronized Collections, CopyOnWriteArrayList, Concurrent Collections
Concurrent Collections ConcurrentHashMap, ConcurrentLinkedQueue, BlockingQueue, CopyOnWriteArraySet
Performance Considerations Time Complexity, Space Complexity, Big-O of Collection Operations
Streams & Collections Stream API Integration, Collectors, Parallel Streams, Mapping/Reducing
Custom Implementations Custom Comparator, Custom Collection, Wrapper Classes
Weak & Special Collections WeakHashMap, IdentityHashMap, EnumMap, Soft References
Advanced Data Structures LinkedHashMap (access order), TreeMap with Custom Comparator, PriorityQueue Customization
Best Practices Choosing Right Collection, Fail-Fast vs Fail-Safe, Memory Considerations
Garbage Collection & References WeakReference, SoftReference, PhantomReference in Collections
Real-time Use Cases Caching with Maps, Thread-Safe Queues, LRU Cache with LinkedHashMap

Interview question

Basic

  1. What is the Java Collections Framework?
  2. Difference between Collection and Collections in Java?
  3. What are the main interfaces in the Java Collections Framework?
  4. Difference between List, Set, and Map?
  5. What is the difference between Array and ArrayList?
  6. What is the difference between ArrayList and LinkedList?
  7. Difference between HashSet and TreeSet?
  8. What is the difference between HashMap and Hashtable?
  9. What is the difference between HashMap and LinkedHashMap?
  10. What is the difference between HashMap and TreeMap?
  11. What is the default load factor of HashMap?
  12. How does HashMap handle collisions?
  13. What is the initial capacity of HashMap?
  14. What is the difference between fail-fast and fail-safe iterators?
  15. How do you iterate over a List in Java?
  16. How do you sort a List in Java?
  17. How do you reverse a List in Java?
  18. What is the use of Collections utility class?
  19. How do you make a List thread-safe?
  20. What is the difference between synchronized collections and concurrent collections?
  21. What is the difference between ArrayDeque and LinkedList as a Queue?
  22. What is the difference between Stack and Deque?
  23. What is the difference between PriorityQueue and TreeSet?
  24. How does PriorityQueue maintain ordering?
  25. What is the difference between Comparable and Comparator?

Intermediate

  1. Explain how HashMap works internally.
  2. What is the role of hashCode() and equals() in collections?
  3. Why are hashCode() and equals() important in HashMap/HashSet?
  4. What happens if you override equals() but not hashCode()?
  5. What happens if you override hashCode() but not equals()?
  6. What is the difference between shallow copy and deep copy in collections?
  7. How do you create an immutable collection in Java?
  8. What is the difference between unmodifiable and immutable collections?
  9. What are WeakHashMap and its use cases?
  10. How does IdentityHashMap differ from HashMap?
  11. What is EnumSet and EnumMap?
  12. What is the difference between LinkedHashSet and TreeSet?
  13. How does ConcurrentHashMap achieve thread safety?
  14. What is the difference between CopyOnWriteArrayList and ArrayList?
  15. What is the difference between ConcurrentSkipListMap and TreeMap?
  16. What is the difference between BlockingQueue and ConcurrentLinkedQueue?
  17. Explain how LinkedHashMap maintains insertion order.
  18. What is LRU cache and how can you implement it using LinkedHashMap?
  19. What are NavigableMap and NavigableSet?
  20. Explain differences between TreeSet and TreeMap.
  21. How do you synchronize a HashMap?
  22. What is the difference between Collections.synchronizedList and CopyOnWriteArrayList?
  23. What is Spliterator in Java collections?
  24. How do you iterate a map using Java 8 forEach?
  25. How do you convert between arrays and collections?

Advanced

  1. Explain HashMap resizing and rehashing process.
  2. What is the significance of 0.75 load factor in HashMap?
  3. What happens when two keys have the same hashCode in HashMap?
  4. What is the role of linked lists and balanced trees in HashMap buckets (Java 8+)?
  5. Explain the performance differences between ArrayList, LinkedList, and Vector.
  6. How does TreeMap ensure sorting of keys?
  7. Difference between natural ordering and custom ordering in TreeMap/TreeSet?
  8. How does ConcurrentHashMap split data into segments? (Java 7 vs Java 8)
  9. What is the difference between parallelStream() and stream() on collections?
  10. What is a fail-fast iterator? Which collections are fail-fast?
  11. What is a fail-safe iterator? Which collections are fail-safe?
  12. How does CopyOnWriteArrayList work internally?
  13. What are weak references and how does WeakHashMap use them?
  14. How does IdentityHashMap use reference equality?
  15. Explain the difference between Hashtable and ConcurrentHashMap.
  16. How does EnumMap achieve better performance than HashMap?
  17. What are concurrent collections introduced in Java 5?
  18. What is the difference between ArrayBlockingQueue and LinkedBlockingQueue?
  19. How does PriorityBlockingQueue work?
  20. What is DelayQueue and its use cases?
  21. How does LinkedTransferQueue work?
  22. What is the difference between ConcurrentLinkedDeque and ArrayDeque?
  23. How do you implement producer-consumer using BlockingQueue?
  24. How do you avoid ConcurrentModificationException in collections?
  25. Explain the difference between Collections.emptyList() and new ArrayList<>().

Expert

  1. Explain the red-black tree implementation in TreeMap.
  2. How does HashMap deal with hash collisions after Java 8?
  3. What is tail binning in ConcurrentHashMap?
  4. Explain bin migration in ConcurrentHashMap.
  5. What is structural modification in collections?
  6. How does Java?s ForkJoinPool interact with parallel streams on collections?
  7. How do you implement a custom collection in Java?
  8. What interfaces must a custom collection implement?
  9. How do you implement a custom comparator for complex sorting?
  10. How does Spliterator support parallelism in Java collections?
  11. What is the role of characteristics in Spliterator (e.g., ORDERED, DISTINCT, SIZED)?
  12. How do you use Collectors.toMap() without causing IllegalStateException on duplicate keys?
  13. How do you optimize collection performance for read-heavy workloads?
  14. How do you optimize collection performance for write-heavy workloads?
  15. How does ConcurrentSkipListMap ensure thread safety and ordering?
  16. Explain the difference between segment-locking (Java 7) and bucket-level locking (Java 8) in ConcurrentHashMap.
  17. How do you implement a thread-safe LRU cache?
  18. Explain memory overhead of different collections.
  19. How do you implement multi-level sorting using Comparator chaining?
  20. How do you detect and handle memory leaks in collections?
  21. How do you implement an observer pattern with collections?
  22. How does the Stream API integrate with collections?
  23. How do you design collections for large-scale distributed systems?
  24. How do you tune GC behavior for large collections in JVM?
  25. Future of Java collections: how Project Valhalla and new JVM features might affect them?

Related Topics