Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about null keys and values in a HashMap is true?

  • A.A HashMap permits one null key and any number of null values.
  • B.A HashMap permits any number of null keys and any number of null values.
  • C.A HashMap permits null values but rejects a null key with NullPointerException.
  • D.A HashMap rejects both null keys and null values with NullPointerException.

Answer: A

The javadoc states the class permits null values and the null key. Only one null key can exist because keys are unique, while null may appear as a value as often as you like. That is worth remembering because get returning null then cannot distinguish an absent key from one mapped to null.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.