Skip to content
Sharp

Collections · interview question

Which method would you use to remove a key-value pair from a HashMap?

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

Correct answer

D. Remove()

Why

The remove() method is used to delete a key-value pair from a HashMap. The method delete() and discard() do not exist, and clear() removes all entries from the map.

Test yourself on Collections

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

Start free test
All Collections questions →