Govt Exams
HashMap allows null values. The code stores null as the value for key 'key' and retrieves it successfully, printing null.
TreeSet does not allow duplicates. Adding 2 twice means it is stored only once. Final set contains {2, 5, 8}, so size is 3.
ArrayList maintains insertion order and provides O(1) random access via index. LinkedHashMap maintains insertion order but is a Map, not a List.
The containsValue() method checks if the map contains a specified value. containsKey() checks for keys.
ArrayList uses 0-based indexing. Index 1 refers to the second element added, which is "Python".
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.
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.