Collectors API[作成中...]



Collectors API


方法


groupingBy


collecting

public static <T> Collector<T, ?, Long>
    counting() {
        return reducing(0L, e -> 1L, Long::sum);
    }

reducing


アプリケーションアイテム

# [JDK] Collectors API groupBy - 1
## 내용
- Collectors API의 groupBy 메소드를 활용하여 로또 결과 출력 시에 당첨된 등수의 개수를 계산
- 중복된 Collectors 사용을 static import를 사용하여 가독성을 높임
## 링크
- https://velog.io/@jh8579/Stream-API
private LottoResult calculateLottoResult(LottoTickets lottoTickets,
        WinningLottoTicket winningLottoTicket) {
        return lottoTickets.list().stream()
            .map(winningLottoTicket::compareNumbers)
            .collect(collectingAndThen(
                groupingBy(Function.identity(), counting()),
                LottoResult::new));
    }

リファレンス