Skip to content
Sharp

Core Java · interview question

What happens if you try to retrieve a value from a HashMap using a key that is not present?

Multiple choiceMediumchapter-4-curatedpremiumcore-javacode-reading-with-collections
Choose one answer
Answer and explanation

Correct answer

B. Returns null

Why

If a key is not present in the HashMap, the get() method returns null, indicating that no mapping exists for the specified key.

Test yourself on Core Java

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

Start free test
All Core Java questions →