首页 > 编程语言 > 详细

java 中如何声明线程安全的集合 set, map 和list

时间:2016-07-03 15:48:55      阅读:446      评论:0      收藏:0      [点我收藏+]

http://blog.sina.com.cn/s/blog_508938e10102v1ig.html

 

//make thread-safe list
  List MyStrList = Collections.synchronizedList(new ArrayList());
  MyStrList.add("123");
  MyStrList.add("abc");
  //make thread-safe hashset
  Set set=Collections.synchronizedSet(new HashSet());
  set.add(123);
  set.add(456);
  //make thread-safe hashmap
  Map map=Collections.synchronizedMap(new HashMap());
  map.put(1, "thb");
  map.put(12, "bill tang");

 

java 中如何声明线程安全的集合 set, map 和list

原文:http://www.cnblogs.com/whatlonelytear/p/5638082.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!