JAVA之Map操做

        Map<String, Integer> map1=new HashMap<>();
        map1.put("AAA", 100);
        map1.put("BBB", 100);
        Map<String, Integer> map2=new HashMap<>();
        map2.put("AAA", 50);
        Map<String, Integer> map3=new HashMap<>();

        
        for (String key : map1.keySet()) { 
              if(map2.containsKey(key)) {
                  map3.put(key, map1.get(key)-map2.get(key));
              }else {
                  map3.put(key, map1.get(key));
              }
        } 
        System.out.println(map3);
相關文章
相關標籤/搜索