Skip to content
Sharp

Collections · interview question

Which collection in Java should be used to store key-value pairs allowing null values but not null keys?

Multiple choiceEasychapter-4-curatedpremiumcollectionschoosing-the-right-collection
Choose one answer
Answer and explanation

Correct answer

D. HashMap

Why

HashMap allows null values but does not allow null keys. TreeMap also allows null values but sorts the keys. Hashtable does not allow null keys or values.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →