赞
踩
// 多个Map<Long,Integer>, 根据key相同的,value累积求和; public static Map mapCombine(List<Map<Long,Integer>> list) { Map<Long, Integer> map = new HashMap<>(); for (Map<Long,Integer> m : list) { Iterator<Long> it = m.keySet().iterator(); while (it.hasNext()) { Long key = it.next(); if (!map.containsKey(key)) { map.put(key, m.get(key)); } else { map.put(key,(map.get(key)+m.get(key))); } } } return map; }
Integer totalCount = map.values().stream().mapToInt(Integer::intValue).sum(); //values求和
map.entrySet().stream().forEach(x -> {
System.out.println("key: "+x.getKey()+", value: "+x.getValue());
});
result = map.entrySet().stream()
.filter(map -> "hello world".equals(map.getValue()))
.map(map -> map.getValue())
.collect(Collectors.joining()
);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。