주요 메서드
- 스트림 필터링 : filter(), distinct()
- 스트림 변환 : map(), flatMap()
- 스트림 제한 : limit(), skip()
- 스트림 정렬 : sorted()
- 스트림 연산 결과 확인 : peek()
스트림 필터링
- .filter() :
- .distinct() : 해당 스트림에서 중복된 요소가 제거된 새로운 스트림 return
IntStream stream1 = IntStream.of(7, 5, 5, 2, 1, 2, 3, 5, 4, 6);
IntStream stream2 = IntStream.of(7, 5, 5, 2, 1, 2, 3, 5, 4, 6);
// 스트림에서 중복된 요소를 제거함.
stream1.distinct().forEach(e -> System.out.print(e + " "));
System.out.println();
// 스트림에서 홀수만을 골라냄.
stream2.filter(n -> n % 2 != 0).forEach(e -> System.out.print(e + " "));
//7 5 2 1 3 4 6
//7 5 5 1 3 5
'Language > Java' 카테고리의 다른 글
Stream 최종 연산 (0) | 2022.07.19 |
---|---|
Stream 생성 방법 (0) | 2022.07.18 |
Functional Interface & Lambda(작성중) (0) | 2022.07.18 |