Skip to content
Sharp

Core Java · interview question

Which method would you use to efficiently check the presence of a key in a HashMap?

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

Correct answer

A. ContainsKey()

Why

The containsKey() method is specifically designed to check if a key exists in a HashMap, making it efficient and appropriate for this task.

Test yourself on Core Java

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

Start free test
All Core Java questions →