zoukankan      html  css  js  c++  java
  • 向map中追加元素

     1 public class Demo01 {
     2     
     3     public static void main(String[] args) {
     4         
     5         String mapKey = "a";
     6         Map<String, Map<String, Integer>> maps = new ConcurrentHashMap<String,Map<String, Integer>>();
     7         Map<String, Integer> map = new HashMap<String,Integer>();
     8         map.put("aaaa", 1);
     9         map.put("bbbb", 2);
    10         map.put("cccc", 3);
    11         
    12         maps.put("a", map);
    13         
    14         if(maps.containsKey(mapKey)){
    15             Map<String, Integer> tmpMap = maps.get(mapKey);            
    16             tmpMap.put("dddd", 4);    
    17             maps.put(mapKey, tmpMap);
    18         }
    19         
    20         //遍历maps
    21         Iterator<String> it = maps.keySet().iterator();
    22         while(it.hasNext()){
    23             String mapsKey = it.next();        
    24             Map<String, Integer> mapValue = maps.get(mapsKey);
    25             System.out.println(mapValue);
    26         }
    27     }
    28 
    29 }
    30 
    31 输出结果:
    32 {bbbb=2, dddd=4, aaaa=1, cccc=3}
  • 相关阅读:
    Extension Methods(扩展方法)
    linux面试题
    渗透测试 day4
    渗透测试 day3
    渗透测试 day2
    渗透测试 day1
    9.3 网络安全介绍
    9.2 Iptables
    8.30 进程管理
    8.29 linux的网络
  • 原文地址:https://www.cnblogs.com/qlwang/p/7904553.html
Copyright © 2011-2022 走看看