142k views
5 votes
What advantage does HashSet have over TreeSet?

a) Faster sorting
b) Ordered elements
c) No duplicate values
d) Automatic resizing

1 Answer

3 votes

Final answer:

HashSet has the advantage of allowing no duplicate values.

Step-by-step explanation:

The advantage that HashSet has over TreeSet is that it allows for no duplicate values. In a HashSet, each element is unique, meaning that if you try to add a duplicate value, it will not be added. This is useful when you want to store a collection of unique elements.

On the other hand, TreeSet does not allow duplicates either, but it provides the additional feature of ordering the elements. The elements in a TreeSet are stored in sorted order, according to their natural ordering or a custom comparator.

Therefore, the correct answer is c) No duplicate values.

User ImkeF
by
8.6k points