sorting an array list of int arrays in terms of the first and the second element of the int arrays
<pre><code>ArrayList&lt;int[]&gt; segment = new Arraylist&lt;int[]&gt;();
segment.add(new int[]{2,3,1});
segment.add(new int[]{2,1,1});
segment.add(new int[]{1,1,1});
segment.add(new int[]{2,4,1});
segment.add(new int[]{3,3,1});
</code></pre>

<p>What I want to do is sort this ArrayLists according to the first element of each array and if the element is same do the sorting according to the 2nd element of the array/arrays</p>

<p>For instance the above lines of code should be modified to,
(1,1,1)
(2,1,1)
(2,3,1)
(2,4,1)
(3,3,1)</p>

<p>this is what i have so far in temrs of solving this,</p>

<pre><code>    public static void SortSegment(ArrayList&lt;int[]&gt; segment){
        Collections.sort(segment, new Comparator&lt;int[]&gt;() {
             public int compare(int[] a, int[] b) {
                  return (a[0] - b[0]);
             }
        });
    }
</code></pre>

<p>this piece of code sorts the arraylist of int arrays according to the first element of each of the int arrays.
How do i modify it to work for cases where the first element is the same so it takes into consideration the 2nd element?</p>

<p>thanks.</p>