Govt. Exams
Entrance Exams
Collections.synchronizedMap() wraps a Map with synchronized access. However, iteration still requires external synchronization.
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.
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.
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.
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)).
containsAll() returns true for empty collections because mathematically, all elements of an empty set are contained in any set (vacuous truth).
Spliterator provides split() capability enabling efficient parallel stream processing with characteristics advertisement.
LinkedHashMap can be extended and removeEldestEntry() overridden to implement LRU cache eviction policy.
Collections.sort() uses TimSort (hybrid of merge and insertion sort) with O(n log n) worst-case, but QuickSort's worst-case is O(n²).
forEachOrdered() preserves encounter order even in parallel streams, while forEach() doesn't guarantee order.