s-day02-Collections中的addAll和shuffle方法
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
package com.inmind.collections04;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Collections的常用方法
|
||||||
|
static <T> boolean addAll(Collection<? super T> c, T... elements) 将所有指定的元素添加到指定的集合。
|
||||||
|
|
||||||
|
static void shuffle(List<?> list) 使用默认的随机源随机排列指定的列表。
|
||||||
|
*/
|
||||||
|
public class Demo13 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//创建List集合
|
||||||
|
ArrayList<String> lists = new ArrayList<String>();
|
||||||
|
//创建Set集合
|
||||||
|
HashSet<Integer> sets = new HashSet<Integer>();
|
||||||
|
//static <T> boolean addAll(Collection<? super T> c, T... elements) 将所有指定的元素添加到指定的集合。
|
||||||
|
Collections.addAll(lists, "张三", "张三1", "张三2", "张三3", "张三4", "张三5");
|
||||||
|
System.out.println(lists);
|
||||||
|
|
||||||
|
Collections.addAll(sets, 1, 2, 3, 4, 5, 6,6,6,6);
|
||||||
|
System.out.println(sets);
|
||||||
|
|
||||||
|
Collections.shuffle(lists);
|
||||||
|
System.out.println(lists);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user