posted 17 years ago
Hi Gitesh,
The following three are common to TreeSet and HashSet
*Each element must be unique.
*Contains no duplicate elements.
*Elements are not key/value pairs.
Now the last feature is where these differ :
Accessing an element can be almost as fast as performing a similar operation on an array.
This feature makes the choice to be HashSet .
If you are wondering why ..then to give you a hint ...
The HashSet is very fast for searching because of the the hashing .Well this is true for any Hash<table , Map , Set > .
The elements in the TreeSet are kept in a sorted fashion.