Skip to content
Sharp

Core Java · interview question

How does a HashMap determine the bucket in which to store an entry?

Multiple choiceMediumchapter-4-curatedpremiumcore-javaequals-and-hashcode-in-collections
Choose one answer
Answer and explanation

Correct answer

D. It uses the hashCode of the key.

Why

A HashMap uses the hashCode of the key to determine which bucket to store the entry in. This allows the map to efficiently locate the entry when needed. The hashCode is used to compute an index that points to the bucket, optimizing the time complexity of operations.

Test yourself on Core Java

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

Start free test
All Core Java questions →