Govt. Exams
Entrance Exams
subList() returns a view (structural reference) to the original list in O(1) time, not a copy.
ConcurrentHashMap uses segment-based locking allowing safe iteration during concurrent modifications. HashMap throws ConcurrentModificationException.
Records (Java 14+) provide compact syntax for data carriers used with collections, improving performance and readability.
CopyOnWriteArrayList is optimal for read-heavy concurrent operations. It creates copy on write, allowing safe concurrent reads.
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).
In worst case with all collisions stored in linked list, get() becomes O(n). From Java 8, if collisions exceed threshold, linked list converts to balanced tree, making it O(log n).
ArrayList starts with capacity 10. Growth factor is 50% + 1 in older versions, and 1.5x from Java 9 onwards.
Both Iterator and enhanced for loop use fail-fast mechanism and throw ConcurrentModificationException if collection is modified during iteration.
The same withdraw() call behaves differently for SavingsAccount and CurrentAccount based on the actual object type at runtime. This is polymorphism with runtime (dynamic) binding.