码迷,mamicode.com
首页 > 其他好文 > 详细

新笔记

时间:2015-08-12 21:32:57      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

  1. package com.journaldev.util;
  2. import java.util.HashMap;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import java.util.concurrent.ConcurrentHashMap;
  6. public class ConcurrentHashMapExample {
  7. public static void main(String[] args) {
  8. //ConcurrentHashMap
  9. Map<String,String> myMap = new ConcurrentHashMap<String,String>();
  10. myMap.put("1", "1");
  11. myMap.put("2", "1");
  12. myMap.put("3", "1");
  13. myMap.put("4", "1");
  14. myMap.put("5", "1");
  15. myMap.put("6", "1");
  16. System.out.println("ConcurrentHashMap before iterator: "+myMap);
  17. Iterator<String> it = myMap.keySet().iterator();
  18. while(it.hasNext()){
  19. String key = it.next();
  20. if(key.equals("3")) myMap.put(key+"new", "new3");
  21. }
  22. System.out.println("ConcurrentHashMap after iterator: "+myMap);
  23. //HashMap
  24. myMap = new HashMap<String,String>();
  25. myMap.put("1", "1");
  26. myMap.put("2", "1");
  27. myMap.put("3", "1");
  28. myMap.put("4", "1");
  29. myMap.put("5", "1");
  30. myMap.put("6", "1");
  31. System.out.println("HashMap before iterator: "+myMap);
  32. Iterator<String> it1 = myMap.keySet().iterator();
  33. while(it1.hasNext()){
  34. String key = it1.next();
  35. if(key.equals("3")) myMap.put(key+"new", "new3");
  36. }
  37. System.out.println("HashMap after iterator: "+myMap);
  38. }
  39. }





新笔记

标签:

原文地址:http://www.cnblogs.com/lanchun/p/4725493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!