title: Java: Hashset Vs TreeSet - when should I use over the other?
body: <p>All I have been reading lots of blogs on this subject but still I could not get clear idea when to use one over another hashset or tree set.</p>
  
  <p>Taken an example:</p>
  
  <ol>
  <li><p>I have a comparable objects. I have put them in HashSet. Now when (<strong>only when I want</strong>) i want to set to be sorted based on compareTo logic, I can call Collections.sort(object)</p></li>
  <li><p>whereas Treeset by default always use the compareTo or compare(obj1, obj2) <strong>all the time</strong>. Hence performance will be hit with TreeSet but output will be same as #1 (Collections.sort).</p></li>
  </ol>
  
  <p>Is this understanding correct?</p>