Skip to content
Sharp

Collections · interview question

Consider a HashSet with objects whose hashCode always returns the same value. What impact does this have?

Multiple choiceHardchapter-4-curatedpremiumcollectionsset-interface-and-hashset
Choose one answer
Answer and explanation

Correct answer

D. Decreased performance due to collision handling

Why

If all objects have the same hashCode, they will all be placed in the same bucket, leading to linear time complexity for operations, as each element must be checked individually.

Test yourself on Collections

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

Start free test
All Collections questions →