Question 13
Back to Exercise
What is the output of the following Java program?
import java.util.Map;
import java.util.TreeMap;
public class Main {
public static void main(String[] args) {
Map<String, Integer> marks = new TreeMap<>(Map.of("Asha", 91, "Ravi", 35, "Meena", 78, "John", 28, "Zoya", 40));
marks.entrySet().removeIf(e -> e.getValue() < 40);
marks.values().removeIf(v -> v == 40);
marks.keySet().remove("Meena");
System.out.println(marks);
}
}
- A {Asha=91} Correct
- B {Asha=91, Meena=78}
- C {Asha=91, Meena=78, Zoya=40}
- D ConcurrentModificationException
Correct Answer: Option A
entrySet(), values() and keySet() are live views; removing through them removes from the map safely.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!