I have two maps:
Map map1;
Map map2;
I need to receive difference between these maps. Does exist ma
Simple way to do it. if you want complex way, you can change filter to compare value.
Map map1 = new HashMap() {{
put("A", "1");
put("B", "2");
put("C", "3");
}};
Map map2 = new HashMap() {{
put("A", "1");
put("B", "2");
put("D", "3");
}};
Map newList = map1.keySet().stream().filter(str -> !map2.containsKey(str)).collect(Collectors.toMap(v -> v, v -> map1.get(v)));
Map oldList = map2.keySet().stream().filter(str -> !map1.containsKey(str)).collect(Collectors.toMap(v -> v, v -> map2.get(v)));
System.out.println(newList);
System.out.println(oldList);