Skip to content
Sharp

Collections · interview question

What will HashMap's get() method return if you pass a key that doesn't exist in the map?

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

Correct answer

A. Null

Why

When you call get() for a key that doesn't exist in a HashMap, it returns null. This is the default behavior for non-present keys.

Test yourself on Collections

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

Start free test
All Collections questions →