Skip to content
Sharp

Collections · interview question

Why do teams use a HashSet over a List when you need to store a collection of product names in production code?

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

Correct answer

B. Ensures uniqueness of elements

Why

A HashSet does not allow duplicate elements and offers constant time performance for basic operations like add, remove, and contains, making it ideal for ensuring uniqueness.

Test yourself on Collections

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

Start free test
All Collections questions →