A HashMap
allows only one null
key. Is it because it allows only unique keys? Or is there another reason?
3
Why is it confusing? The javadoc for HashMap.put
clearly states:
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
It clearly states what happens when you do a put
with a key which was already in the map. The specific case of key == null behaves in the same way: you can’t have two different mappings for the null key (just like you can’t for any other key). It’s not a special case, for the context of your question.