title: Efficient way of sorting a list of tuples in java
body: <p>Given is a generic datatype whick looks like this: <code>HashMap&lt;EdgeTuple, Double&gt; edgeList</code> where tuple is a class EdgeTuple and Double is a weight which is not important for the task: </p>
  
  <pre><code>class EdgeTuple{
      int label1;
      int label2;
      public EdgeTuple(int label1, int label2){
          int min = Math.min(label1, label2);
          int max = Math.max(label1, label2);
          this.label1 = min;
          this.label2 = max;
      }
  }
  </code></pre>
  
  <p>So as you can see the tuples are already having the smaller value on first position. What I want to do is to sort the list which final entry order should look like this:</p>
  
  <p>entry 0: [(0,something);some_weight]</p>
  
  <p>entry 1: [(1,something);some_weight]</p>
  
  <p>...</p>
  
  <p>entry n-1: [(last_value,something);some_weight]</p>
  
  <p>So basically what i need to do is to sort the tuples ascending on their first value. 
  I have red the most liked existing answers on this topic but still could not find anything satisfying. </p>
  
  <p>One possible solution is to lean on a comparator, something like this:</p>
  
  <pre><code>Comparator&lt;Tuple&gt; myComparator = new Comparator&lt;Tuple&gt;() {
      public int compare(Tuple t1, Tuple t2) {
          //the comparison rules go here
      }
  };
  Collections.sort(tupleList, myComparator);
  </code></pre>
  
  <p>The comparison of each pair of tuples does not seem quiet efficient. So my question is, do You know any other ways to sort? Maybe some new datatypes which provide a suitable more performant interface for the given task?</p>
  
  <p>Thanks </p>