Arrays.sort 自定义Comparator的使用
int[][] arr = new int[][]{{3},{6},{5},{4},{1},{2}}; Arrays.sort(arr, (a, b) -> a[0] - b[0]); // 自定义Comparator由小到打排序 for (int i = 0; i < 6; i++) System.out.println(Arrays.toString(arr[i]));
输出:
[1]
[2]
[3]
[4]
[5]
[6]