Which Collections utility method creates an immutable empty list?
Answer: A
Collections.emptyList() returns an immutable, empty list. Option B also works but is more verbose. Option C creates mutable list, and Option D creates mutable list from array.
Q.62Medium
In what scenario would you use a ConcurrentHashMap instead of HashMap?
Answer: B
ConcurrentHashMap uses bucket-level locking (segment locking in Java 7, node-level in Java 8+) allowing concurrent reads/writes, making it thread-safe without synchronizing the entire map.
Q.63Hard
What does the containsAll() method of Collection return for an empty collection?
Answer: A
containsAll() returns true for empty collections because mathematically, all elements of an empty set are contained in any set (vacuous truth).
Q.64Medium
Consider: Set<Integer> set = new HashSet<>(Arrays.asList(1,2,3,2,1)); System.out.println(set.size()); What is the output?
Answer: B
HashSet removes duplicates. The list [1,2,3,2,1] is converted to a set containing only unique elements {1,2,3}, so size is 3.
Q.65Medium
Which method in NavigableMap returns a view of the map in descending order?
Answer: A
descendingMap() method of NavigableMap returns a reverse-ordered view. reverseMap() doesn't exist in Collections Framework.
Advertisement
Q.66Medium
What is the advantage of using LinkedList over ArrayList for frequent insertions at the beginning?
Answer: A
LinkedList provides O(1) insertion at the beginning (head), while ArrayList requires O(n) time to shift elements. Both support nulls and LinkedList uses more memory due to node pointers.
Q.67Hard
How does Java 8+ handle hash collisions in HashMap differently?
Answer: B
Java 8+ introduced tree nodes: when a bucket's linked list size exceeds TREEIFY_THRESHOLD (8), it converts to a Red-Black tree for better performance (O(log n) vs O(n)).
Q.68Hard
What is the behavior of WeakHashMap when a key is no longer strongly referenced?
Answer: B
WeakHashMap uses weak references for keys. When a key is no longer strongly referenced elsewhere, it becomes eligible for garbage collection, and its entry is removed from the map.
Q.69Hard
Which of these operations is guaranteed to be atomic in ConcurrentHashMap?
Answer: B
putIfAbsent() is an atomic operation. Options A and C-D are compound operations that are not atomic and can have race conditions between checks and modifications.
Q.70Easy
What is the primary purpose of the Comparator interface in Collections Framework?
Answer: B
Comparator interface allows defining custom comparison logic for sorting. It provides compare(T o1, T o2) method to establish custom ordering independent of the object's natural order.
Q.71Hard
In Java 2024-25, which enhancement improved record support in collections?
Answer: B
Java 21+ enhanced sealed classes and pattern matching, allowing records to be used with pattern matching in collection operations and switch statements for type-safe data handling.
Q.72Easy
Which interface in Java Collections Framework is used to maintain insertion order while allowing duplicates?
Answer: A
List interface maintains insertion order and allows duplicate elements. ArrayList, LinkedList, and Vector are common implementations.
Q.73Easy
What is the time complexity of get() operation in HashMap in average case?
Answer: C
HashMap provides O(1) average case time complexity for get, put, and remove operations due to hash-based indexing.
Q.74Easy
Which collection class is synchronized and thread-safe by default?
Answer: B
Hashtable is a legacy synchronized collection class. For modern applications, ConcurrentHashMap is preferred over Hashtable.
Q.75Easy
What does the PriorityQueue in Java Collections Framework guarantee?
Answer: C
PriorityQueue is a min-heap by default where elements are retrieved based on priority, not insertion order.
Q.76Medium
Which method is used to remove all elements from a Collection that satisfy a given predicate?
Answer: C
The removeIf() method was introduced in Java 8 to remove elements based on a given Predicate condition.
Q.77Medium
What is the key difference between TreeSet and HashSet?
Answer: B
TreeSet implements SortedSet and maintains elements in sorted order with O(log n) operations. HashSet has O(1) average operations but no order guarantee.
Q.78Easy
Consider: List<String> list = new ArrayList<>(); list.add("Java"); list.add("Python"); What will list.get(1) return?
Answer: B
ArrayList uses 0-based indexing. Index 1 refers to the second element added, which is "Python".
Q.79Medium
Which interface should be implemented to define custom sorting in Collections.sort()?
Answer: A
The Comparable interface allows objects to define their natural ordering by implementing compareTo() method.
Q.80Medium
What does Collections.unmodifiableList() return?
Answer: A
Collections.unmodifiableList() returns a read-only view of the list. Any modification attempts throw UnsupportedOperationException.