java array list sorting

Integer array and int array interchange  mutual conversion of List, Integer[], int[] in Java - Zhihu

Use Integer wrapper class Integer[] nsndo={1,2,6,1,3};

        Integer[] nsndo={1,2,6,1,3};
        System.out.println(Arrays.toString(nsndo));
        Arrays.sort(nsndo, new Comparator<Integer>() {

            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
            
        });
        System.out.println(Arrays.toString(nsndo));

Output results

[1, 2, 6, 1, 3]
[6, 3, 2, 1, 1]

Guess you like

Origin blog.csdn.net/qq_41704436/article/details/132125482