ı am trying to merge more than one hashmaps also sum the values of same key, ı want to explain my problem with toy example as follows
HashMap
Assume that you have many HashMaps: HashMap map1, map2, map3;
HashMap map1, map2, map3;
Then you can use Java 8 streams:
List> mapList = Arrays.asList(map1, map2, map3); Map combinedMap = mapList.stream() .flatMap(map -> map.entrySet().stream()) .collect(Collectors.groupingBy(Entry::getKey, Collectors.summingInt(Entry::getValue)));