Skip to content
Sharp

Collections · interview question

Why might a poorly implemented hashCode() method impact the performance of a HashMap?

Multiple choiceHardchapter-4-curatedpremiumcollectionsmap-interface-and-hashmap
Choose one answer
Answer and explanation

Correct answer

B. It could lead to many keys being placed in the same bucket, causing collision.

Why

A poorly implemented hashCode() method that results in many keys hashing to the same bucket will increase the time complexity of get() and put() operations due to collisions, degrading performance from O(1) to O(n).

Test yourself on Collections

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

Start free test
All Collections questions →