集合(25):Collections类

集合(25):Collections类

1、概述
针对集合操作的工具类
2、案例
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/*
        针对与集合创建的工具类(最常用的方法,将线程不安全的集合转成线程安全的)
 */
public class CollectionsDemo1 {
    public static void main(String[] args) {
        ArrayList<String> strings = new ArrayList<>();

        List<String> strings1 = Collections.synchronizedList(strings);

        strings1.add("hello");
        strings1.add("world");
        strings1.add("java");
        strings1.add("bigdata");
        strings1.add("hadoop");

        System.out.println(strings);
        System.out.println(strings1);
    }
}
            执行结果如下:
                        [hello, world, java, bigdata, hadoop]
                        [hello, world, java, bigdata, hadoop]

                        Process finished with exit code 0
练习题
模拟斗地主洗牌和发牌:
	对牌进行排序
	并同时使用Map,List,Set等集合,可以知道什么时候使用哪种集合
posted @ 2022-01-05 22:07  阿伟宝座  阅读(42)  评论(0)    收藏  举报