java Collections,Arrays工具类集合

Collections工具类集合

  1. void shuffle(List list)
    打乱集合顺序
  2. void sort(List list)
    集合排序

demo:

public class CollectionsDemo {
    public static void main(String[] args){
        List intList = new ArrayList<>();
        intList.add(1);
        intList.add(2);
        intList.add(3);
        intList.add(4);
        intList.add(5);
        Collections.shuffle(intList);
        for (Integer integer : intList) {
            System.out.println(integer);
        }

        Collections.sort(intList);
        for (Integer integer : intList) {
            System.out.println(integer);
        }
    }
}

Arrays工具类集合

  1. 数组转List asList();
  2. 排序 sort();
  3. 转换为字符串toString();
    public void  arrayDemo(){
        int[] nums = {1,2,3,4,5,6,7,8,9,0};

        List intList = Arrays.asList(1,2,3,4,5,6,7,8,9,0);

        Arrays.sort(nums);
        for (int num : nums) {
            System.out.println(num);
        }
        
        String str = Arrays.toString(nums);
        System.out.println(str);
    }

你可能感兴趣的:(java Collections,Arrays工具类集合)