Skip to content
Sharp

Core Java · interview question

In a large HashMap, what is a potential drawback of all keys having the same hashCode?

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

Correct answer

D. Performance degrades to that of a linked list.

Why

If all keys have the same hashCode, they are stored in the same bucket, degrading performance to O(n) for operations, similar to a linked list. Hash-based collections rely on hashCode to evenly distribute entries.

Test yourself on Core Java

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

Start free test
All Core Java questions →