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