Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday, 12 December 2016

What is difference between HashSet and TreeSet In Java ?


Here we will discuss all the differences between HashSet and TreeSet In Java.


HashSet
TreeSet
HashSet internally uses HashMap.
TreeSet internally uses TreeMap.
HashSet does’nt maintain insertion order of elements.
TreeSet by default maintain natural order of elements.
HashSet allows null elements.
TreeSet not allows null elements.
HashSet is not rich in functionality as comparison with TreeSet.
TreeSet is rich in functionality because it has some methods like pollFirst(), pollLast(), first(), last(), ceiling(), lower(), etc.
HashSet uses equal() method for camparison.
TreeSet uses campareTo() method for camparison.
HashSet is much faster than TreeSet.
Its speed is slow than HashSet.
It is backed by HashTable.
It is backed by Red Black Tree.

Some similarities between HashSet and TreeSet are as follows:

HashSet
TreeSet
It doesn’t allow duplicate elements.
It doesn’t allow duplicate elements.
It is not synchronized and thread-safe.
It is not synchronized and thread-safe.
It is fail-fast iterator.
It is fail-fast iterator.


     
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment