Govt Exams
Thread.sleep() pauses execution for a specified milliseconds, while yield() is a hint to the scheduler that the current thread is willing to yield its turn.
LinkedList implements Queue with FIFO behavior. poll() removes and returns 10. peek() returns 20 without removing it. Queue now contains [20, 30].
TreeMap implements NavigableMap and SortedMap, storing key-value pairs in sorted order of keys using a Red-Black tree structure.
LinkedHashMap extends HashMap and uses the same hash table for storage, maintaining O(1) average-case get operation. The doubly-linked list only maintains insertion order.
PriorityQueue is a heap-based implementation where elements are ordered based on their priority determined by natural ordering or a custom comparator provided during initialization.
TreeSet maintains elements in sorted order using a Red-Black tree internally, providing O(log n) for add, remove, and contains operations.
SortedSet interface guarantees sorted order and no duplicates. TreeSet is the primary implementation of SortedSet.
TreeMap.headMap(10) returns a view of all entries with keys strictly less than 10. It's exclusive of the provided key.
Fail-fast iterators throw ConcurrentModificationException if the collection is modified during iteration (except via iterator.remove()).
LinkedList provides O(1) operations for adding/removing at both ends via addFirst(), addLast(), removeFirst(), removeLast().