标签:ash get put sys 输出 rgs add list shm
public class Main {
public static void main(String[] args) {
List<Map> lists = new ArrayList<>(10);
Map<String, Object> m1 = new HashMap<>(16);
m1.put("age", 1);
m1.put("name", 1);
m1.put("sex", 1);
lists.add(m1);
Map<String, Object> m2 = new HashMap<>(16);
m2.put("age", 12);
m2.put("name", 1);
m2.put("sex", 13);
lists.add(m2);
Map<String, Object> m3 = new HashMap<>(16);
Set keys = m1.keySet();
keys.forEach((e) -> {
lists.forEach((li) -> {
if (m3.get(e) == null) {
m3.put(e.toString(), 0);
}
int sum = (Integer) m3.get(e) + (Integer) li.get(e);
m3.put(e.toString(), sum);
});
});
System.out.println(m3);
}
}
输出结果
{sex=14, name=2, age=13}
标签:ash get put sys 输出 rgs add list shm
原文地址:https://www.cnblogs.com/zhenghengbin/p/9452377.html