💜 toList 반환형식 List 스트림의 모든 항목을 리스트로!
ex) List dishes = menuStream.collect(toList());
💜 toSet 반환형식 Set 스트림의 모든 항목을 중복없는 집합으로 수집
ex) Set dishes = menuStream.collect(toSet());
💜 toCollection 반환형식 Collection 스트림의 모든 항목을 제공하는 컬렉션으로
ex) Collection dishes = menuStream.collect(toCollection(), ArrayList::new);
💜 counting 반환형식 long 스트림의 항목 수 계산
ex) long howManyDishes = menuStream.collect(counting());
💜 summingInt 반환형식 Integer 스트림 항목 정수 프로퍼티 값을 더해줌
ex) int totalCalories = menuStream.collect(summingInt(Dish::getCalories));
💜 averagingInt 반환형식 Double 스트림 항목 정수 프로퍼티 평균값 계산
ex) double avgCalories = menuStream.collect(averagingInt(Dish::getCalories));
💜 summarizingInt 반환형식 IntSummaryStatistics 스트림 항목의 최대값, 최소값, 합계, 평균 등 통계를 냄
ex) IntSummaryStatistics menuStatistics =
menuStream.collect(summarizingInt(Dish::getCalories));
💜 joing 반환형식 String 스트림 각 항목에 toString메서드를 호출한 문자열을 연결
ex) String menu = menuStream.map(Dish::getName).collect(joining(", "));
💜 maxBy 반환형식 Optional 주어진 비교자를 이용해서 최대값을 Optional로 감싼 값으로 반환하고 요소가 없는 경우 Optional.empty()
ex) Optional fattest = menuStream.collect(maxBy(comparingInt(Dish::getCalories)));
💜 minBy Optional 위에 maxby랑 똑같음
ex) Optional lightest = menuStream.collect(minBy(comparingInt(Dish::getCalories)));
💜 reducing 누적자를 초기값으로 설정 BinaryOperator로 스트림의 요소를 반복적으로 누적자와 합쳐서 하나의 값으로 리듀싱
ex) int total = menuStream.collect(reducing(0, Dish::getCalories, Integer::sum));
💜 collectingAndThen 다른 컬렉터를 감싸고 그 결과에변환 함수 적용
ex) int howMany = menuStream.collect(collectingAndThen(toList(), List::size));
💜 groupingBy Map<K, List> 하나의 프로퍼티값을 기분으로 스트림 항목을 그룹화 기준 프로퍼티값을 결과 맵의 키로 사용.
ex) Map<Dish.Type, List> dishesByType =
menuStream.collect(groupingBy(Dish::getType));
💜 partitioningBy Map<Boolean, List> 프레디케이트를 스트림의 각 항목에 적용한 결과로 항목 분할
ex) Map<Boolean, List> vegetarianDishes =
menuStream.collect(partitioningBy(Dish::isVegetarian));