You have several options.
For instance, given the following data set (sorry for its simplicity):
Map<String, Object> map1 = HashMap.of("key1", "value1", "key2", "value2");
Map<String, Object> map2 = HashMap.of("key3", "value3", "key4", "value4");
Map<String, Object> map3 = HashMap.of("key5", "value5", "key6", "value6");
List<Map<String, Object>> list = List.of(map1, map2, map3);
You can combine the different Map
s with fold
, for instance:
Map<String, Object> result = list.fold(HashMap.empty(), (m1, m2) -> m1.merge(m2));
You can use reduce
as well:
Map<String, Object> result = list.reduce((m1, m2) -> m1.merge(m2));
Both of them use the Map
merge
method. There is an overloaded version of this method that allows you to define how collisions should be resolved.