在这里插入代码片
```public static void main(String[] args) {
//1.测试ArrayList集合
// List list=new ArrayList<>();
//解决方式一
// List list=new Vector<>();
//解决方式二 利用集合工具类来完成
// List list= Collections.synchronizedList(new ArrayList<>());
//方式三 利用juc中的CopyOnWriteArrayList
//---------------------------------------------------------------------
//测试set
// Set set=new HashSet<>();
//解决方式一
// Set set=Collections.synchronizedSet(new HashSet<>());
//方式二
// Set set=new CopyOnWriteArraySet<>();
// for(int i=0;i<30;i++) {
// new Thread(() -> {
// //添加数据
// set.add(UUID.randomUUID().toString().substring(0,10));
// //取出数据
// System.out.println(set);
// //产生原因是因为在在添加数据的时候有的线程在取出数据
// }).start();
// }
//--------------------------------------------------------------------------
//测试hashMap
// Map map=new HashMap<>();
//解决方法
// Map map=Collections.synchronizedMap(new HashMap<>());
Map map=new ConcurrentHashMap<>();
for(int i=0;i<30;i++) {
String value = String.valueOf(i);
new Thread(() -> {
//添加数据
map.put(value,UUID.randomUUID().toString().substring(0,10));
//取出数据
System.out.println(map);
//产生原因是因为在在添加数据的时候有的线程在取出数据
}).start();
}
}