数组排序

    xiaoxiao2021-04-19  113

    package com.wlf.array; import java.util.Arrays; import java.util.Comparator; public class ArraySort { public static void main(String[] args) { Integer[] intArr = new Integer[] { 23, 34, 4, 57, 12 }; // 对数组排序由小到大 Arrays.sort(intArr); // 对数组排序由大到小 Arrays.sort(intArr, new Comparator () { public int compare(Integer o1, Integer o2) { if (o1.intValue() > o2.intValue()) { return -1; } if (o1.intValue() < o2.intValue()) { return 1; } else { return 0; } } }); } }
    转载请注明原文地址: https://ju.6miu.com/read-676022.html

    最新回复(0)