23 June 2021

#Collections

#Collections

Key Concepts


S.No Topic Sub-Topics
1CollectionsCollection, Collection vs Collections, Hierarchy, Root Interfaces, Use Cases
2Core InterfacesCollection, List, Set, Map, Queue, Marker Interfaces
3Iterable & IteratorsIterable, Iterator, ListIterator, forEach, Fail-fast
4List InterfaceIndexed Access, Order, Duplicate, add/remove, ListIterator
5ArrayListInternal Array, resize, load factor, random access, use cases
6LinkedListDoubly Linked, node structure, insertion cost, Deque support, use cases
7Vector & StackLegacy Classes, Synchronization, performance, Stack methods, use cases
8Set InterfaceUniqueness, hashing logic, duplicate detection, equals, hashCode
9HashSetHash table, buckets, collisions, load factor, iterator order
10LinkedHashSetInsertion order, doubly-linked buckets, access order, LRU
11TreeSetSorted, NavigableSet, Red-Black Tree, compareTo, Comparator
12Map InterfaceKey/Value, uniqueness of key, null handling, entrySet, hashing
13HashMapHashing, buckets, resizing, tree bins, load factor, collisions
14LinkedHashMapOrder, access-order mode, LRU cache, removeEldestEntry, use cases
15TreeMapRed-Black Tree, sorting keys, NavigableMap, comparator, range queries
16ConcurrentHashMapSegments, Lock-free, CAS, performance, concurrency model
17WeakHashMapGC aware keys, WeakReference, caching, memory leaks
18IdentityHashMapReference equality, == vs equals, special use cases, pitfalls
19EnumMap & EnumSetBitwise storage, speed, memory, enum key benefits
20Queue InterfaceFIFO behavior, offer/poll, peek, priority queue, Deque
21Deque InterfaceDouble-ended queue, addFirst/addLast, stack vs queue
22PriorityQueueHeap, priority logic, compareTo, ordering, use cases
23BlockingQueueProducer-consumer, put/take methods, thread safety, use cases
24CopyOnWrite CollectionsCopyOnWriteArrayList, snapshot, safety, performance trade-offs
25Collections Utility Classsort, reverse, shuffle, binarySearch, unmodifiable, synchronized
26Stream CollectorstoList, toSet, toMap, groupingBy, partitioningBy, mapping
27Custom ComparatorComparator interface, compare method, chaining, reversed, nullsFirst
28Big-O PerformanceComplexity, add/remove, get, contains, load factor, resizing
29Choosing Right CollectionDecision matrix, use cases, performance tuning, trade-offs
30Best Practices & PatternsImmutability, safe iteration, fail-fast, defensive copy, caching

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


   Collections Basic   
   Array   
   ArrayList   
   LinkedList   
   HashSet   
   LinkedHashSet   
   TreeSet   
   HashMap   
   LinkedHashMap   
   TreeMap   
   ConcurrentHashMap   
   WeakHashMap   
   IdentityHashMap