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

1. Collections Framework Overview

  1. What is the Java Collections Framework?
  2. What is the difference between Collection and Collections?
  3. What are the main interfaces in Collections Framework?
  4. What are the advantages of using Collections over arrays?
  5. Explain fail-fast vs fail-safe iterators.
  6. What is the difference between Iterator and Enumeration?
  7. What is the difference between Iterable and Iterator?
  8. What is the hierarchy of Collection interfaces?
  9. What is the difference between List, Set, and Map?
  10. What is the difference between shallow copy and deep copy in collections?

2. List Implementations

  1. What is the difference between ArrayList and LinkedList?
  2. When to use ArrayList over LinkedList?
  3. When to use LinkedList over ArrayList?
  4. How does Vector differ from ArrayList?
  5. What is the default capacity of ArrayList?
  6. How does ArrayList grow internally?
  7. What is CopyOnWriteArrayList and its use case?
  8. How does Stack work in Java?
  9. What are the advantages/disadvantages of LinkedList?
  10. How do you synchronize an ArrayList?

3. Set Implementations

  1. What is the difference between HashSet and TreeSet?
  2. How does HashSet internally work?
  3. Does HashSet allow null elements?
  4. How does LinkedHashSet maintain order?
  5. How does TreeSet maintain order?
  6. What is the difference between HashSet and LinkedHashSet?
  7. Can TreeSet contain null values?
  8. What is the time complexity of add(), remove(), and contains() in HashSet?
  9. How do you implement a custom comparator for TreeSet?
  10. How does HashSet handle duplicate elements?

4. Map Implementations

  1. What is the difference between HashMap and Hashtable?
  2. Can HashMap have null keys and values?
  3. How does LinkedHashMap maintain insertion order?
  4. What is TreeMap and how is it ordered?
  5. How does HashMap handle collisions?
  6. What is the load factor in HashMap?
  7. What is the difference between HashMap and ConcurrentHashMap?
  8. What is WeakHashMap and when to use it?
  9. What is IdentityHashMap and its use cases?
  10. How does EnumMap differ from other maps?

5. Queue & Deque

  1. What is the difference between Queue and Deque?
  2. How does PriorityQueue work internally?
  3. What is ArrayDeque and when to use it?
  4. What is BlockingQueue and its implementations?
  5. What are DelayQueue and its use cases?
  6. What is ConcurrentLinkedQueue?
  7. How do you implement Producer-Consumer using BlockingQueue?
  8. What is PriorityBlockingQueue and when to use it?
  9. How does LinkedBlockingQueue differ from ArrayBlockingQueue?
  10. What is the difference between FIFO and LIFO collections?

6. Iteration & Traversal

  1. How do you iterate over a List in Java?
  2. What is ListIterator and how is it different from Iterator?
  3. What are Spliterators and their use?
  4. How do you iterate over a Map in Java?
  5. How do you remove elements while iterating a collection?
  6. What is forEachRemaining() in Iterator?
  7. How do you convert an Iterator to a List?
  8. What is the difference between sequential and parallel iteration?
  9. How do you use streams for iteration?
  10. How do you detect ConcurrentModificationException?

7. Utility Classes

  1. What is the role of Collections class?
  2. What is the role of Arrays class?
  3. How do you sort a List using Collections?
  4. What is binarySearch() in Collections?
  5. How do you shuffle a List?
  6. What is unmodifiableCollection in Collections?
  7. What is singletonList in Collections?
  8. How do you make a List thread-safe using Collections?
  9. How do you create a synchronizedMap using Collections?
  10. What are checked collections?

8. Streams & Collections

  1. How do you convert a List to a Stream?
  2. How do you filter elements in a collection using streams?
  3. What is the difference between map() and flatMap()?
  4. How do you find duplicates in a List using streams?
  5. How do you use Collectors.groupingBy()?
  6. How do you use Collectors.partitioningBy()?
  7. How do you collect a stream into a Set?
  8. How do you collect a stream into a Map?
  9. How do you use reduce() with collections?
  10. What are parallel streams and when to use them?

9. Concurrency in Collections

  1. What is the difference between synchronized collections and concurrent collections?
  2. How does ConcurrentHashMap achieve thread safety?
  3. What is the difference between Hashtable and ConcurrentHashMap?
  4. How does CopyOnWriteArrayList handle concurrency?
  5. What are the advantages of concurrent collections?
  6. What is ConcurrentSkipListMap?
  7. How does ConcurrentLinkedDeque work?
  8. How do you avoid ConcurrentModificationException?
  9. What is the difference between fail-fast and fail-safe iterators?
  10. How does BlockingQueue ensure thread safety?

10. Advanced Concepts & Best Practices

  1. What are weak references in collections?
  2. How does WeakHashMap work with garbage collection?
  3. Why should mutable objects not be used as HashMap keys?
  4. Why is it important to override hashCode() and equals()?
  5. What are immutable collections and how to create them?
  6. How do you implement a custom collection in Java?
  7. What are the best practices for choosing the right collection?
  8. How do you implement LRU Cache using LinkedHashMap?
  9. What are common pitfalls in using Java Collections?
  10. How do you handle memory leaks in collections?

Related Topics