Practice mode Java

How many null keys can a java.util.HashMap hold?

Correct answer C. At most one

Explanation

HashMap permits null values and a single null key. Since keys must be unique, putting a second entry with a null key simply replaces the first one's value. This differs from Hashtable and ConcurrentHashMap, which reject null keys outright by throwing NullPointerException, a common point of confusion when replacing one map type with another.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.