有一个流List
我不知道该怎么办
你可以尝试这样的事情:
List<TreeMap<Key, BigDecimal>> data = ...;
Map<Key, BigDecimal> result = data.stream()
.flatmap(tree -> tree.entrySet().stream())
.collect(
Collectors.toMap(
e -> e.getKey(),
e -> e.getValue(),
(a, b) -> a.add(b) // BigDecimal with the same key will be summed.
)
);