我有两个地图
Map<A, B> mapA
Map<B, List<C>> mapB
我希望将MapA中的值与MapB中的键进行匹配,然后对它们进行合并。合并后的结果应该是:
Map<A,List<C>> mapC
我想知道如何在Java8中使用流来实现。
为了简单起见,我的情况下,A、B和C都是字符串。
我有两个地图
Map<A, B> mapA
Map<B, List<C>> mapB
Map<A,List<C>> mapC
我想知道如何在Java8中使用流来实现。
为了简单起见,我的情况下,A、B和C都是字符串。
Map<A,List<C>> mapC = new HashMap<>();
mapA.forEach((key,value)->mapC.put(key, mapB.get(value)));
mapC = mapA.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> mapB.get(e.getValue())));
map.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> mapB.get(e.getValue())))
- shmosel