Java — Store elements with no duplicates and natural order. Which interface provides this capability?

Difficulty: Easy

Correct Answer: java.util.Set

Explanation:


Introduction / Context:
Different collection interfaces in Java define different rules for storage: duplicates, ordering, and key-value mappings.



Given Data / Assumptions:

  • Requirement: no duplicates.
  • Requirement: natural order access.


Concept / Approach:
Set interface represents collections with no duplicate elements. SortedSet (e.g., TreeSet) provides natural ordering.



Step-by-Step Reasoning:

Map → stores key-value pairs, not individual elements.List → allows duplicates, preserves insertion order, not natural ordering.Collection → general root interface; does not guarantee uniqueness or order.


Why Other Options Are Wrong:
Only Set ensures uniqueness; TreeSet (implementation) also provides natural order.



Final Answer:
java.util.Set

More Questions from Objects and Collections

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion