title: Best way to sort a Set?
body: <p>i have a class representing cars:</p>
  
  <pre><code>public class Car implements Comparable&lt;Car&gt; {
      String name;
      int value;
      ...
      @Override
      public int compareTo(Car o) {
          return name.compareTo(o.name);
      }
  }
  </code></pre>
  
  <p>and another class representing races:</p>
  
  <pre><code>public class Race {
      cars = new HashSet&lt;Car&gt;();
      ...
      public Collection&lt;Car&gt; sortByName() {
          List&lt;Car&gt; carList = new ArrayList&lt;&gt;(cars);
          Collections.sort(carList);
          return carList;
      }
  }
  </code></pre>
  
  <p>Its my implementation to sorting the Set, i know there is a TreeSet but i dont know how to compare it by TreeSet instead of HashSet, because if i used TreeSet i couldnt find method comprator() in it, can anyone help me if im doing well or if not how to use TreeSet?</p>