Skip to content
Sharp

Collections · interview question

What happens when you try to add a duplicate element to a HashSet?

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

Correct answer

C. The add operation fails silently

Why

HashSet does not allow duplicate elements; if you try to add a duplicate, the add operation fails silently, and the set remains unchanged.

Test yourself on Collections

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

Start free test
All Collections questions →