Elements in a TreeSet are ordered according to their natural ordering (see java.lang.Comparable interface). Optionally, they can be ordered with a java.util.Comparator provided to the TreeSet. Elements in a HashSet are unordered. Checkout the Javadoc for the iterator() methods on both classes to learn more.
Hashset vs Treeset?
I've always loved trees, that nice `O(n*log(n))` and the tidiness of them. However, every software engineer I've ever known has asked me pointedly why I would use a `TreeSet`. From a CS background, I don't think it matters all that much which you use, and I don't care to mess around with hash functions and buckets (in the case of `Java`). In which cases should I use a `HashSet` over a `TreeSet`?
Follow
1
Add comment
More
Report
1 Expert Answer
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.