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]

 

posted @ 2021-09-08 16:00  蜜铀  阅读(439)  评论(0编辑  收藏  举报