Skip to content
Sharp

Collections · interview question

Given a HashMap<String, Integer> map, what will map.get(null) return if null is not a key in the map?

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

Correct answer

B. Null

Why

In a HashMap, if you use get() with a key that does not exist, it returns null — this includes if the key is null and not present in the map.

Test yourself on Collections

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

Start free test
All Collections questions →