Skip to content
Sharp

Collections · interview question

Which method would you use to check if a HashMap contains a specific key?

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

Correct answer

A. ContainsKey()

Why

The containsKey() method is used to check if a particular key is present in the HashMap. It returns true if the key is found, otherwise false.

Test yourself on Collections

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

Start free test
All Collections questions →