Skip to content
Sharp

Collections · interview question

When iterating over a HashMap, which method provides access to both keys and values?

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

Correct answer

D. EntrySet()

Why

The entrySet() method returns a set view of the mappings contained in the map. This allows you to iterate over both keys and values using Map.Entry.

Test yourself on Collections

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

Start free test
All Collections questions →