Java 8 Stream groupingBy with custom logic
问题 I have a list of Records . Which has two fields: LocalDateTime instant and a Double data . I want to groupBy all the records by Hour and create a Map<Integer, Double> . Where the keys (Integer) are hours and values(Double) are last Data of that hour - first Data of that hour. What I have done so far is following: Function<Record, Integer> keyFunc = rec->rec.getInstant().getHour(); Map<Integer, List<Record>> valueMap = records.stream().collect(Collectors.groupingBy(keyFunc)); I want the value