title: Sorting ArrayList
body: <p>Since I'm just starting with JAVA, I'm curious what is the best option for implementing sorting in JAVA (for ArrayLists). Below I provide my PHP code.</p>
  
  <pre><code>public int cmp($a, $b) {
      if ( $a[0] &lt; $b[0] ) return 1;
      else if ( $a[0] &gt; $b[0] ) return -1;
      else if ( $a[1] &lt; $b[1] ) return 1;
      else if ( $a[1] &gt; $b[1] ) return -1;
      else return 0;
  }
  
  $selected = array();
  
  for ($i=0; $i&lt;$len; $i++) {
      $rank = getRank();
      $cub = getCub_len();
      $selected[] = array($rank,$cub);
  }
  
  uasort($selected, 'cmp')
  </code></pre>
  
  <p>Well, I wrote the following code in JAVA:</p>
  
  <pre><code>ArrayList&lt;ArrayList&lt;Double&gt;&gt; selected = new ArrayList&lt;ArrayList&lt;Double&gt;&gt;();
  ArrayList&lt;Double&gt; rank = new ArrayList&lt;Double&gt;();
  ArrayList&lt;Double&gt; cub = new ArrayList&lt;Double&gt;();
  
  for (int i=0; i&lt;len; i++) {
   rank.add(getRank(i));
   cub.add(getCub(i));
  }
  
  selected.add(0,rank);
  selected.add(1,cub);
  </code></pre>
  
  <p>How to sort <code>selected</code> in the proper way (similarly to PHP function <code>cmp</code>)?</p>