Skip to content
Sharp

Collections · interview question

Which collection is the best fit if you need to maintain a sorted catalog of product prices in an e-commerce application?

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

Correct answer

B. TreeSet

Why

TreeSet maintains a sorted order of its elements, making it ideal for storing product prices in sorted order. HashSet and LinkedHashSet do not sort, and ArrayList would require manual sorting.

Test yourself on Collections

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

Start free test
All Collections questions →