Skip to content
Sharp

Collections · interview question

You need to store product IDs and ensure no duplicates, with the ability to retrieve them in sorted order. Which collection do you choose?

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

Correct answer

D. TreeSet

Why

TreeSet maintains elements in a sorted order and ensures that all elements are unique, making it the ideal choice for storing product IDs with these requirements.

Test yourself on Collections

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

Start free test
All Collections questions →