使用Arrays.sort排序

增序排序

Integer arr[] = {3,2,1,7};

Arrays.sort(arr,0,4);

System.out.println(Arrays.toString(arr));

倒序排列

Integer[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5};

Arrays.sort(a,0,4,Collections.reverseOrder());

for(int arr:a) {
System.out.print(arr + " ");
}

猜你喜欢

转载自www.cnblogs.com/wwenwei/p/11641734.html