package: java.util.Arrays
int[] newArr = Arrays.copyOf(arr, arr.length);
int[] a = {1, 2, 3};
System.out.println(Arrays.toString(a));
// output:
// [1, 2, 3]
Arrays.fill(a, 0);
// a:
// {0, 0, 0}
int[] arr = new int[] {1,3,5,4};
Arrays.sort(arr) // 升序排列
Arrays.sort(arr, Reverse
自定义排序的实现方法:
Arrays.sort(T[] a, Comparator<? Super T> c) 匿名类 (或者外部类)
int[][] boxTypes;
Arrays.sort(boxTypes, new Comparator<int[]>() {
public int compare(int[] o1, int[] o2) {
return o2[1]-o1[1];
};
});
lambda
//降序
Arrays.sort(arr, (a, b) -> {
//返回值>0交换
return b-a;
});
Comparator.comparingInt
Arrays.sort(boxTypes, Comparator.comparingInt(o -> o[1]));
Collection.reverseOrder
// 降序
Integer[] arr={9,8,7,6,5,4,3,2,1};
Arrays.sort(arr,Collections.reverseOrder());
数组部分排序: