最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

使用流添加持續(xù)時間的數(shù)組列表

使用流添加持續(xù)時間的數(shù)組列表

慕田峪9158850 2023-07-19 16:05:53
我有一個秒表類來測量生成報告所需的時間:public class Stopwatch {  public String report;  public Instant startTime;  public Instant endTime;  public Duration duration;}運行報告時,會收集時間和持續(xù)時間:private ArrayList<Stopwatch> _reportStats;最后我想知道所有報告的總持續(xù)時間,例如:Duration total = Duration.ZERO; // was null;for (Stopwatch s: _reportStats) {  total = total.plus(s.duration);}除了我想使用流和減少,但我無法得到正確的語法:Duration total = _reportStats.stream().reduce(... syntax ...);
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經(jīng)驗 獲得超6個贊

您可以將sumreduce標識值 (Duration.ZERO ) 一起使用,并將其定義Duration.plus為累加器:

Duration total = _reportStats.stream()
        .map(Stopwatch::getDuration)
        .reduce(Duration.ZERO, Duration::plus);


查看完整回答
反對 回復 2023-07-19
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號