我想在對一組數據進行分組后收集統計信息,但我不知道是否可以Map<String, DoubleSummaryStatistics> menuStatistics = menuPrices.parallelStream() .collect(Collectors.groupingBy(cp -> dt1.format(cp.getUpdateDate())), Collector.of(DoubleSummaryStatistics::new));因為我有一些編譯問題:Multiple markers at this line - The method of(Supplier<R>, BiConsumer<R,T>, BinaryOperator<R>, Collector.Characteristics...) in the type Collector is not applicable for the arguments (DoubleSummaryStatistics::new) - The constructed object of type DoubleSummaryStatistics is incompatible with the descriptor's return type: R
1 回答
莫回無
TA貢獻1865條經驗 獲得超7個贊
您需要使用Collectors.summarizingDouble(),假設您的類( 的元素類型Stream)有一些double您想要計算統計數據的屬性:
Map<String, DoubleSummaryStatistics>
menuStatistics =
menuPrices.parallelStream()
.collect(Collectors.groupingBy(cp -> dt1.format(cp.getUpdateDate()),
Collectors.summarizingDouble(cp -> cp.getSomeDoubleValue())));
添加回答
舉報
0/150
提交
取消
