Skip to content
Sharp

Collections · interview question

What does the 'contains' method of a HashSet use to check for the presence of an element?

Multiple choiceMediumchapter-4-curatedpremiumcollectionscollection-performance-basics
Choose one answer
Answer and explanation

Correct answer

B. Hash code and equals method

Why

HashSet uses the hash code to narrow down the potential location and then checks equality using the equals method to confirm the presence of an element.

Test yourself on Collections

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

Start free test
All Collections questions →