如何在java中使用任意数量的元素对数组进行排序?

如何在java中使用任意数量的元素对数组进行排序?,java,sorting,Java,Sorting,如何在java中对具有任意数量元素的数组进行排序 我创建了一个数组,允许用户选择元素的数量,但我不知道如何排序 这是数组代码 Scanner input = new Scanner(System.in); System.out.print("Enter the size of the array: "); int r = input.nextInt(); int[] list = new int[r];

如何在java中对具有任意数量元素的数组进行排序

我创建了一个数组,允许用户选择元素的数量,但我不知道如何排序

这是数组代码

Scanner input = new Scanner(System.in);
            System.out.print("Enter the size of the array: ");
            int r = input.nextInt();
            int[] list = new int[r];
            init(list);
你可以试试

Arrays.sort(list);

不想显得粗鲁,但你可以通过谷歌搜索你的确切问题标题来得到答案。是什么阻止了你这么做?不,他们创建了数组并用seem方法对其排序,对不起,这不是真的。这是一个涵盖面很广的基本主题。我能用另一种方法试试吗?@TalalAlosaimi你试过吗?我能问你什么是平均值列表吗?@TalalAlosaimi列表是你在代码中使用的变量。将其作为参数传递给函数Arrays.sort。