What is Hashset and Tresset?

Hashset is the execution of the set interface and is backed by hashmap, while on the other hand, Tree set executes sorted sets and is backed by TreeMap.

Difference between Hashset and Treeset in Java

S. No.

Hash Set

Tree Set

1 The Hash set is executed with the help of a HashTable. The tree set is executed with the help of a tree structure.
2 It does not authorise a heterogeneous object. It authorises a heterogeneous object.
3 It permits a null object. It does not permit the null object.
4 To compare two objects, we use the equals method. To compare two objects, we use the compare method.
5 It does not support any order TreeSet supports an object in sorted order.

Keep learning and stay tuned to get the latest updates on GATE along with GATE Preparation Books & GATE Answer Key and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*