Collections常用的API
最常用的兩個
public static <T> boolean addAll (Collection<T>, T...elements)
批量添加蝇率,把可變參數(shù)中的數(shù)據(jù)添加到指定的集合中public static void shuffle (List<?> list)
打亂List集合中元素的順序
package com.wyx;
import java.util.ArrayList;
import java.util.Collections;
//Collections常用的API
public class Demo5 {
public static void main(String[] args) {
//1.批量添加鞋既,適用于Collection接口
ArrayList<Integer> list = new ArrayList<>();
Collections.addAll(list, 1, 2, 3, 4, 5, 6);
System.out.println(list);//[1, 2, 3, 4, 5, 6]
//2.隨機(jī)打亂順序 適用于List集合
Collections.shuffle(list);
System.out.println(list);//[4, 6, 5, 2, 1, 3]
}
}