Java Map MCQs with answers
79 questions tagged Java Map, each with the correct answer and an explanation. Page 1 of 4.
- Which method is used to get a value or compute and store if absent?
- What will happen if you try to modify a map created with `Map.of()`?
- What does `entrySet().iterator()` return?
- Which type of Map allows duplicate values but unique keys?
- Which of the following is true about `Collections.unmodifiableMap(map)`?
- Which method in the Map interface is used to copy all mappings from one map to another?
- Which of these maps throws a `NullPointerException` when `null` is used as a key?
- What is returned by the `size()` method of a Map?
- Which Map implementation uses hash table and linked list to maintain order?
- Which method in the Map interface is used to remove a mapping only if the key is mapped to a specific value?
- Which Map is ideal for maintaining access order?
- Which of the following operations is NOT supported by `Map.of()`?
- Which of the following guarantees thread-safety?
- Which Map implementation is sorted and allows null values but not null keys?
- Which is the default load factor of HashMap?
- What will `map.getOrDefault(“key”, “default”)` return if key is not found?
- What is returned by `computeIfPresent()` in Map?
- What happens if you pass a null key to `TreeMap`?
- Which method returns a shallow copy of a Map?
- What does `Map.Entry` represent in Java?