Skip to content
Sharp

Collections · interview question

Which Java collection should you choose for a product catalog if you need to frequently check if a product ID exists and order does not matter?

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

Correct answer

C. HashSet

Why

A HashSet provides O(1) average time complexity for contains operations, which is ideal when you frequently check for the existence of elements and do not care about order.

Test yourself on Collections

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

Start free test
All Collections questions →