JDK 自带排序(Arrays.sort(数组名))与自行编写的降序
jdk 自带的排序 Arrays.sort(数组名) 只能进行升序排列
可以与自己写的降序 配合使用
import java.util.Arrays;public class Test1 {//jdk 自带升序public static void m1(int [] arr1) {Arrays.sort(arr1);}public static int[] m2(int[] arr1 ) {int [] arr2 = new int[arr1.length];//降序实现for (int i = 0,j = arr1.length-1; i < arr1.length; i++,j--) {arr2[j] = arr1[i];}return arr2;}public static void main(String[] args) {int [] arr1 = {123,2432,41,21,4325};//此处属于引用传递//实现了升序m1(arr1);System.out.println("升序:"+Arrays.toString(arr1));//自行编写降序int [] arr2 = m2(arr1);System.out.println("降序:"+Arrays.toString(arr2));}
}
结果截图: