Skip to content
Sharp

Collections · interview question

Which method would you use to add an element to a HashMap?

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

Correct answer

D. Put()

Why

The put() method is used to add a key-value pair to a HashMap. The other methods are not defined for HashMap operations.

Test yourself on Collections

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

Start free test
All Collections questions →