Skip to content
Sharp

Core Java · interview question

In a HashSet, what determines the position of an element?

Multiple choiceMediumchapter-4-curatedpremiumcore-javacode-reading-with-collections
Choose one answer
Answer and explanation

Correct answer

C. Element's hash code

Why

A HashSet uses the hash code of an element to determine its position within the set, allowing for constant-time performance for basic operations like add, contains, and remove.

Test yourself on Core Java

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

Start free test
All Core Java questions →