例子如下:
Map<String,Object> h1 = new HashMap<>();
h1.put("12","fdsa");
h1.put("123","fdsa");
h1.put("124","fdsa");
h1.put("125","fdsa");
Map<String,Object> h2 = new HashMap<>();
h2.put("h12","fdsa");
h2.put("h123","fdsa");
h2.put("h124","fdsa");
h2.put("h125","fdsa");
Map<String,Object> h3 = new HashMap<>();
h3.put("h312","fdsa");
h3.put("h3123","fdsa");
h3.put("h3124","fdsa");
h3.put("h3125","fdsa");
List<Map<String,Object>> lists = new ArrayList<>();
lists.add(h1);
lists.add(h2);
lists.add(h3);
想用java 8 把lists里面的map合并成一个新的map:
Map<String,Object> haNew = new HashMap<>(); // 包含了h1,h2,h3的内容
请问该如何实现,谢谢.
我自己使用下面的方式实现了一个:
private Map<String,Object> megerListMap(List<Map<String,Object>> listsMap){
Map<String,Object> map = new HashMap<>();
listsMap.forEach(x->{
x.forEach((y,z)->{
map.put(y, z);
});
});
return map;
}
但想要更简单的方式.
子衿沉夜
POPMUISE
相关分类