Entrance Exams
Govt. Exams
poll() returns null if the queue is empty, while remove() throws NoSuchElementException.
Hashtable is a legacy synchronized collection class. HashMap, ArrayList, and TreeSet are not synchronized by default.
HashMap has a default initial capacity of 16 and a load factor of 0.75.
Set interface does not allow duplicate elements, while List, Queue, and Collection support duplicates.
CopyOnWriteArrayList is optimal for read-heavy concurrent operations. It creates copy on write, allowing safe concurrent reads.
Java 9 introduced factory methods like List.of(), Set.of(), Map.of() for creating immutable collections.
List list = Arrays.asList(5, 2, 8, 1);
All three approaches work correctly for reverse sorting. Options A, B, and C are all valid Java code.
LinkedHashMap with accessOrder=true maintains access-order. get() moves the element to the end (LRU cache behavior).
removeIf(Predicate) removes all elements that satisfy the given predicate condition (Java 8+).
LinkedList provides O(1) insertions/deletions at any position. ArrayList is O(n) for middle insertions due to shifting.