공부
[Java] Stream GroupBy
승가비
2021. 11. 5. 15:57
728x90
import java.util.*;
import java.util.stream.*;
class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("Hello");
list.add("World");
Map<String, Long> counted = list.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
System.out.println(counted);
}
}
https://stackoverflow.com/questions/25441088/how-can-i-count-occurrences-with-groupby
How can I count occurrences with groupBy?
I want to collect the items in a stream into a map which groups equal objects together, and maps to the number of occurrences. List<String> list = Arrays.asList("Hello", "Hello...
stackoverflow.com
https://akageun.github.io/2019/08/06/java-stream-groupby.html
[jdk 8]Stream GroupBy 사용하기.
언제나 개발하기를 즐기는 개발자 입니다.
akageun.github.io
728x90