title: Java: sort a list of lists
body: <p>I have a list of lists of points ie: <code>List&lt;List&lt;Point&gt;&gt;</code>.
  e.g.: </p>
  
  <pre><code>List&lt;Point&gt; lp;
  List&lt;List&lt;Point&gt;&gt; Llp;
  Llp.add(lp);
  </code></pre>
  
  <p><code>lp</code>would be the first line of my matrix (x=0). <code>Llp</code>is the whole matrix.</p>
  
  <p>I want to get the list ascendingly sorted according to both x and y of each point. I only managed to get the internal list sorted but not the whole list. Can anyone help me please? Thank you. Here is my code to sort the internal list (ie. the first line of the matrix) according to y.</p>
  
  <pre><code>private void ord_horiz (List&lt;Point&gt; tab)
  {
      boolean ordered_horiz = false;
      int size = tab.size();
  
      while(!ordered_horiz)
      {
          ordered_horiz = true;
  
          for(int i=0 ; i &lt; size-1 ; i++)
          {
              if(tab.get(i).y &gt; tab.get(i+1).y)
              {
                  swap(tab, i, i+1);
                  ordered_horiz = false;
              }
          }
          size--;
      }   
  }
  
  private void swap(List&lt;Point&gt; tab, int ind1, int ind2) 
  {
      Point c;
      c = tab.get(ind1); 
      tab.set(ind1, tab.get(ind2));
      tab.set(ind2, c);
  }
  </code></pre>
  
  <p>Here is the code I wrote so far: </p>
  
  <pre><code>Collections.sort(tab,new Comparator&lt;List&lt;Point&gt;&gt;(){
  
  
          @Override
          public int compare(List&lt;Point&gt; o1, List&lt;Point&gt; o2) {
              if(o1 != null &amp;&amp; o2 !=null)
              {
                  Point var1 = o1.get(0);
                              int var1_x = var1.x;
                              int var1_y = var1.y;
                  Point var2 = o2.get(0);
                              int var2_x = var2.x;
                              int var2_y = var2.y;
  
                              Integer.compare(var1_x, var2_x);
                              Integer.compare(var1_y, var2_y);
                  return /* What shall I return ? */;                 
              }
              return 0;
          }
      });
  </code></pre>
  
  <p>Here is a screenshot of my console output. I want that point to be sorted.
  <a href="http://imageshack.us/scaled/large/515/38zy.png" rel="noreferrer">http://imageshack.us/scaled/large/515/38zy.png</a></p>