地图流到地图

地图流到地图,第1张

地图流到地图

我的语法可能有些偏离,但是flatMap应该为您完成大部分工作:

Map<String, Long> toMap(Stream<Map<String, Long>> stream) {    return stream.flatMap (map -> map.entrySet().stream()) // this would create a flattened    // Stream of all the map entries      .collect(Collectors.toMap(e -> e.getKey(),          e -> e.getValue())); // this should collect        // them to a single map}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5561761.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存