集合(一)-Java中Arrays.sort()自定义数组的升序和降序排序
默认升序 package peng; import java.util.Arrays; public class Testexample { public static void main(String[] args) { int[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5}; Arrays.sort(a); for(int arr:a) { System.out.print(arr + " "); } } } 自定义 利用Collections.reverseOrder()方法: package peng; import java.util.Arrays; import java.util.Collections; public class Testexample { public static void main(String[] args) { integer[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5}; Arrays.sort(a,Collections.reverseOrder()); for(int arr:a) { System.out.print(arr + " "); } } } 实现Comparator接口的复写compare()方法,代码如下: package peng; import java