Skip to content
Sharp

Collections · interview question

What will happen if you try to insert a null key into a HashMap?

Multiple choiceMediumchapter-4-curatedpremiumcollectionsmap-interface-and-hashmap
Choose one answer
Answer and explanation

Correct answer

A. The null key will be inserted successfully.

Why

HashMap allows one null key and any number of null values. Therefore, inserting a null key will succeed unless the map implementation specifically restricts it.

Test yourself on Collections

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

Start free test
All Collections questions →