Multiple choice technology web technology

What is the difference between a treeset and hashset in Java?

  1. In a treeset data are placed in order

  2. In a hashset data are placed in order

  3. Both are same

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

TreeSet implements the SortedSet interface and maintains elements in ascending order using a red-black tree. HashSet does not guarantee any order and uses hash codes for storage, providing O(1) average case performance.