Entrance Exams
Govt. Exams
ArrayList uses 0-based indexing. Index 1 refers to the second element added, which is "Python".
TreeSet implements SortedSet and maintains elements in sorted order with O(log n) operations. HashSet has O(1) average operations but no order guarantee.
The removeIf() method was introduced in Java 8 to remove elements based on a given Predicate condition.
PriorityQueue is a min-heap by default where elements are retrieved based on priority, not insertion order.
Hashtable is a legacy synchronized collection class. For modern applications, ConcurrentHashMap is preferred over Hashtable.
HashMap provides O(1) average case time complexity for get, put, and remove operations due to hash-based indexing.
List interface maintains insertion order and allows duplicate elements. ArrayList, LinkedList, and Vector are common implementations.
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.
Comparator interface allows defining custom comparison logic for sorting. It provides compare(T o1, T o2) method to establish custom ordering independent of the object's natural order.
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.