What is the difference between hashset and treeset ?

1The underlying data structure is Hashtable1The underlying data structure is balanced tree
2Heterogeneous objects are allowed2       Heterogeneous objects are not allowed  by defalut
3Insertion order is not preserved and it is based on hashcode of the objects3   Insertion order is not preserved and all the objects are inserted according to some sorting order.
4null insertion is possible4   As the first element only null insertion is   possible and in all other cases we will get NullPointerException (After null insertion other insertion not possible)

No comments:

Post a Comment