title: Sorting Datastructures using comparator
body: <p>I am trying to sort an array (<code>ads</code>, of type <code>ETstrain</code>) by one of the instance variables (<code>distancefrom</code>). How can I do this? I have tried using a comparator and then a sorting function. Is there a better way/ do I have any logical fallacies?  </p>
  
  <pre><code>abstract class distanceComparator implements Comparator&lt;ETstrain&gt; {
      @Override
      public int compare(ETstrain a, ETstrain b) {
      return a.distancefrom &lt; b.distancefrom ? -1 : a.distancefrom == b.distancefrom ? 0 : 1;
          }
  }
  
  public static &lt;ETstrain&gt; void sort(ads[] a,
          Comparator&lt;ETstrain&gt; b)
  </code></pre>