Eventually I got the answer, but it puzzled me for a while.
Why does the following code throws NullPointerException when run?
import java.util.*; c
You are assigning int p to the return value of m.put(). But put() returns null in this situation, and you can't assign an int to null.
int p
m.put()
put()
null
int
From the Javadocs for HashMap.put():
HashMap.put()
Returns: previous value associated with specified key, or null if there was no mapping for key.