over 5 years ago
I am explaining the difference between HashSet and TreeSet in Java.
First of all they both come from the same family. They implement the Set Interface.
HashSet hashSet= new HashSet();
O/P: [one, Remember, Thing]
On the other hand in TreeSet, elements are sorted and it is the main characteristic of the TreeSet.
TreeSet<String> treeSet= new TreeSet<String>();
O/P: [One, Remember, Thing]
HashSet allows null values on the other hand TreeSet does not allow.
TreeSet throws NullPointerException.
Time Performance for the general operations like add,size of HashSet is constant.
But for HashSet its log(n) time cost for the same.
As we go to the speed, HashSet is very faster than TreeSet
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Terms of Service
| © copyright 2021 FindNerd.com. All rights reserved.
Sign up using