Skip to content
Sharp

Collections · interview question

When iterating over a HashMap, which method provides the most efficient way to traverse its entries?

Multiple choiceMediumchapter-4-curatedpremiumcollectionsiteration-and-traversal
Choose one answer
Answer and explanation

Correct answer

C. Using entrySet()

Why

Using entrySet() is the most efficient way to traverse a HashMap's entries as it provides direct access to both keys and values without additional lookup operations.

Test yourself on Collections

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

Start free test
All Collections questions →