按行排序: 对二维数组行排序,直接调用Arrays.sort就行: private static int [][] sortRows(int[][] arr) {//行排序 for (int i = 0; i < arr.length; i++) { Arrays.sort(arr[i]); } return arr; } 或者使用比较器创建内部类: Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { return o1[0] - o2[0]; } }); 按列排序: 对列排序(从小到大),使用比较器创建内部类: Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { return o1[1] - o2[1]; } }); 如果想要按列从大到小排序: Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { return o2[1] - o1[1]; } }); 最简单的写法:使用lambda表达式 // 对行: Arrays.sort(arr, Comparator.comparingInt(o -> o[0])); // 对列: Arrays.sort(arr, Comparator.comparingInt(o -> o[1]));