Collections和Collection的区别:

集合的工具类:Collections是类,封装了Set,List,Map操作的工具方法。

常用的集合类:

HashSet/ArrayList/HashMap在多线程情况下都不安全的,

解决方案:

List  list =Collections.synchronizedList(new ArrayList());

Map map =Collections.synchronizedMap(new HashMap());

Set set=Collections.synchronizedSet(new HashSet());

要做迭代时得使用synchronized

传入一个不安全的线程,返回一个安全的线程

 

posted on 2018-03-23 16:00  曾经的一去不返  阅读(182)  评论(0)    收藏  举报

导航