/ / = = = = = = = = = = = = = = new two source data, and to join the list = = = = = = = = = = = = = = = = = =

Map<String, Object> map1 = new HashMap<>(); map1.put("id", 1); Map1. Put (" name ", "a"); map1.put("age", 12); Map1. Put (" gender ", "male"); Map<String, Object> map2 = new HashMap<>(); map2.put("id", 2); Map2. Put (" name ", "b"); map2.put("age", 13); Map2. Put (" gender ", "female"); List<Map<String, Object>> sourceList = new ArrayList<>(); sourceList.add(map1); sourceList.add(map2); / / = = = = = = = = = = = = = = new merge into three belt of new data, to join the list = = = = = = = = = = = = = = = = = = Map < String, Object > newMap1 = new HashMap < > (); newMap1.put("id", 1); NewMap1. Put (" name ", "a"); newMap1.put("age", 10); newMap1.put("birthday", "2011-09-29"); Map<String, Object> newMap2 = new HashMap<>(); newMap2.put("id", 2); NewMap2. Put (" name ", "b"); newMap2.put("age", 11); newMap2.put("birthday", "2010-09-29"); Map<String, Object> newMap3 = new HashMap<>(); newMap3.put("id", 3); NewMap3. Put (" name ", "c"); newMap3.put("age", 19); newMap3.put("birthday", "2002-09-29"); List<Map<String, Object>> newList = new ArrayList<>(); newList.add(newMap1); newList.add(newMap2); newList.add(newMap3); ** * SourceList has two data points, NewList has three data points ** We want to merge the two maplists, try to keep all the data in each map, if the map has the same id, we want to merge the map, * if the other key is the same, * if the source key is null, then use the newList * (name and age are key conflicts, name and age are the same). But age is different) * and eventually merged into a single mapList to achieve the following: * [{" birthday ":" 2011-09-29 ", "gender" : "male", "name" : "a", "id" : 1, "age" : 12}, * {" birthday ", "2010-09-29", "gender" : "female", "name" : "b", "id" : 2, "age" : 13}, * {"birthday":"2002-09-29","name":" c ","id":3,"age":19}] */ / List<Map<String, Object>> list = New arrayList <>(); list.addAll(sourceList); list.addAll(newList); List<Map<String,Object>> combine = list.stream(). Collect (GroupingBy (Group->) Group. Get ("id").toString()); group. Get ("id").toString(); group. Object>> bbb.entrySet () // get Set< map.entry <String, List<Map<String, Stream ().map(m-> {List< map <String, Object>> map <String, Object>> map <String, Object> bbb.stream ().map(m-> {List< map <String, Object>> map <String, Object> collect = m.getValue(). Stream () // O.EntrySet () Set< map.entry <String, Object>> .flatMap(o -> o.entrySet().stream()).filter(e -> e.getValue() ! = null)// If the value is not null, // (m1, m2) -> M1 means that the value uses m1 if the key is the same as m1 == m2. Collect (Collectors.tomap (map.entry ::getKey). Map.Entry::getValue, (m1, m2) -> m1 )); return collect; }).sorted(Comparator.comparing(m -> m.get("id").toString())).collect(Collectors.toList()); System.out.println(json.tojonstring (combine)); This paper related reference link: https://segmentfault.com/q/1010000010380854