亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Java8 中收集統計信息

在 Java8 中收集統計信息

蠱毒傳說 2021-09-29 16:33:51
我想在對一組數據進行分組后收集統計信息,但我不知道是否可以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())));


查看完整回答
反對 回復 2021-09-29
  • 1 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號