• Hash Set is faster than Tree Set and should be the preferred choice if sorting of elements is not required.
  • Hash Set allows null object but Tree Set doesn’t allow null object and its throws Null pointer Exception why because Tree Set Use compareTo() method to compare keys and compareTo() will throw null pointer exception.
  • Hash Set allows a heterogeneous object, Tree Set not allowed heterogeneous object otherwise it will throw Class Cast Exception.
  • if you want to sorted set then it is better to add elements to the Hash Set and then convert it into Tree Set rather than creating a Tree Set and adding an element to it .
  • Hash Set is implemented Hash Table and Tree Set implements using a Tree Structure.
  • HashSet can hold one null key, Tree Set Cant insert null value.