如何使用流读取包含以空格分隔的浮点数的txt文件,获取总和、平均值、最大值和最小值?

How to read a txt file containing floating-point numbers separated by spaces using streams to obtain the sum, average, maximum, and minimum?

try (Stream<String> lines = Files.lines(file.toPath()).parallel()) {
    lines.map(line -> Stream.of(line.split(" ")) //Something something more         
} 

这是我目前所拥有的,我无法弄清楚如何获取对象流并将其映射到双流以便检索摘要统计信息

这是仅使用地图来回答这个问题的解决方案:

lines.map(line -> Stream.of(line.split(" ")))
.reduce((e1, e2) -> Stream.concat(e1, e2)).get()
.mapToDouble(Double::parseDouble)
.summaryStatistics()

评论中给出了使用flatMap的解决方案
谢谢大家的帮助!

我不确定你的意思是不是:

try (Stream<String> lines = Files.lines(file.toPath()).parallel()) {
    lines.flatMap(line -> Stream.of(line.split(" ")))
            .mapToDouble(Double::parseDouble)
            .summaryStatistics();
}