Multiple aggregate functions in Java 8 Stream API

前端 未结 4 1457
甜味超标
甜味超标 2021-02-08 14:17

I have a class defined like

public class TimePeriodCalc {
    private double occupancy;
    private double efficiency;
    private String atDate;
}
4条回答
  •  时光说笑
    2021-02-08 14:41

    You can chain multiple attributes like this:

    Collection collector = result.stream().collect(Collectors.groupingBy(p -> p.getAtDate(), Collectors.averagingInt(p -> p.getOccupancy())));
    

    If you want more, you get the idea.

提交回复
热议问题