Skip to content
Sharp

Collections · interview question

If you need to frequently check the existence of items in a catalog by their names, which collection offers the best performance?

Multiple choiceHardchapter-4-curatedpremiumcollectionschoosing-the-right-collection
Choose one answer
Answer and explanation

Correct answer

D. HashSet

Why

HashSet provides constant time complexity O(1) for lookup operations, which is optimal for frequently checking the existence of elements. TreeSet, while sorted, has higher lookup time complexity of O(log n).

Test yourself on Collections

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

Start free test
All Collections questions →