← Quiz: HashMap and Maps: all 10 questions
Quiz: HashMap and Maps · Question 1 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
Map<String, Integer> m = new HashMap<>();
m.put("x", 1);
m.put("x", 2);
System.out.println(m.size() + " " + m.get("x"));
}
}
- A.2 1
- B.1 2
- C.2 2
- D.1 1
Answer & explanation
Correct answer: 1 2
The second put replaces the value for the same key.
Can you get the rest right without peeking?
Take the timed Quiz: HashMap and Maps quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →