Try the following:
int[][] test = new int[][]{{2,5}, {4,18}, {1,7},{9,3}};
Arrays.sort(test, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o2[0] - o1[0];
}
});
I have not tested this, but it should work. Please note that you can cancel the subtraction to change the top-down.
source
share