Skip to content
Sharp

Core Java · interview question

How can you iterate over a HashMap to get both keys and values?

Multiple choiceMediumchapter-4-curatedpremiumcore-javacode-reading-with-collections
Choose one answer
Answer and explanation

Correct answer

D. Using entrySet()

Why

Using entrySet() allows iteration over the key-value pairs of a HashMap, providing access to both keys and values in each entry.

Test yourself on Core Java

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

Start free test
All Core Java questions →