Govt Exams
forEachOrdered() preserves encounter order even in parallel streams, while forEach() doesn't guarantee order.
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.
Collections.frequency() correctly handles null values and returns the count of null elements in the collection.
lower() returns the greatest element < given element. floor() returns <= element.
Iterator.next() throws NoSuchElementException when hasNext() returns false and next() is called.
TreeSet maintains sorted order (O(log n) insertion/deletion) using a Red-Black tree structure.
ListIterator extends Iterator and provides bidirectional traversal using previous() and next() methods.
CopyOnWriteArrayList maintains insertion order and is thread-safe. It creates a copy of the array on modification.