Skip to content
Sharp

Collections · interview question

Two Product objects compare equal by SKU, but their hashCode() values differ. What bug is likely in HashSet or HashMap usage?

Multiple choiceHardchapter-4-curatedpremiumcollectionsequals-and-hashcode-in-collections
Choose one answer
Answer and explanation

Correct answer

A. Logically equal entries may appear twice or fail lookup unexpectedly

Why

If equal objects produce different hash codes, they may land in different buckets. That breaks the assumptions hash-based collections rely on and can make duplicates or missing lookups appear like mysterious collection bugs.

Test yourself on Collections

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

Start free test
All Collections questions →