Govt. Exams
Entrance Exams
WeakHashMap uses weak references for keys. When a key is no longer referenced elsewhere, it becomes eligible for garbage collection and is automatically removed from the map.
CopyOnWriteArrayList creates a snapshot for iterators, so modifications after iterator creation don't affect the iteration. Iterator sees only original elements: A and B.
EnumSet is specialized for Enum constants and uses bit vectors internally, providing O(1) operations with minimal memory overhead.
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.