import java.util.*; public static void sortIntArray(int[][] arObjects, final int[] arOrders) { Arrays.sort(arObjects, new Comparator<Object>() { public int compare(Object oObjectA, Object oObjectB) { int[] arTempOne = (int[])oObjectA; int[] arTempTwo = (int[])oObjectB; for (int i = 0; i < arOrders.length; i++) { int k = arOrders[i]; if (arTempOne[k] > arTempTwo[k]) { return 1; } else if (arTempOne[k] < arTempTwo[k]) { return -1; } else { continue; } } return 0; } }); }
The call method is as follows:
Public static void main (string [] ARGs) {int array [] [] = new int [] [] {12, 34, 68, 32, 9, 12,545 }, {34, 72, 82, 57, 56, 0,213}, {12, 34, 68, 32, 21,945, 23}, {91, 10, 3, 2354, 73, 34, 18}, {12, 83,189, 26, 27, 98, 33}, {47, 23,889, 24,899, 23,657}, {12, 34, 68,343,878,235,768}, {12, 34, 98, 56, 78, 12,546}, {26, 78,236 5, 78, 34,256,873}; sortintarray (INT [] [], int []) (array, new int [] {0, 1}); // compare the values based on the first column. If the values are the same, compare the values of the second column for (INT I = 0; I <array. length; I ++) {for (Int J = 0; j <array [I]. length; j ++) {system. out. print (array [I] [J]); system. out. print ("\ t");} system. out. println ();}}
Note: This article Reprinted from: http://blog.sina.com.cn/s/blog_5a15b7d101014ngm.html