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));
}
リファレンス
Reference
この問題について(Collectors API[作成中...]), 我々は、より多くの情報をここで見つけました
https://velog.io/@jh8579/Stream-API
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
public static <T> Collector<T, ?, Long>
counting() {
return reducing(0L, e -> 1L, Long::sum);
}
# [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));
}
リファレンス
Reference
この問題について(Collectors API[作成中...]), 我々は、より多くの情報をここで見つけました
https://velog.io/@jh8579/Stream-API
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
Reference
この問題について(Collectors API[作成中...]), 我々は、より多くの情報をここで見つけました https://velog.io/@jh8579/Stream-APIテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol