我的语法可能有些偏离,但是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}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)