스트림의 모든 요소에 지정된 작업 수행 - forEach(), forEachOrdered()
void forEach(Consumer<? super T> action)
void forEachOrdered(Consumer<? super T> actoin)
IntStream.range(1, 10).sequential().forEach(System.out::print);
IntStream.range(1, 10).sequential().forEachOrdered(System.out::print);
IntStream.range(1, 10).parallel().forEach(System.out::print);
IntStream.range(1, 10).parallel().forEachOrdered(System.out::print);
조건 검사 - allMatch(), anyMatch(), noneMatch()
boolen allMatch (Predicate<? super T> predicate)
boolean anyMatch (Predicate<? super T> predicate)
boolean noneMatch (Predicate<? super T> predicate)
boolean hasFailedStu = stuStream.anyMatch(s -> s.getTotalScore() <= 100);
조건에 일치하는 요소 찾기 - findFirst(), findAny()
Optional<T> findFirst()
Optional<T> findAny()
Optional<Student> result = stuStream.filter(s -> s.getTotalScore() <= 100).findFirst();
Optional<Student> result = parallelStream.filter(s -> s.getTotalScore() <= 100).findAny();
스트림의 요소를 하나씩 줄여가며 누적연산 수행 - reduce()
int count = intStream.reduce(0, (a,b) -> a + 1);
int sum = intStream.reduce(0, (a,b) -> a + b);
int max = intStream.reduce(Integer.MIN_VALUE, (a,b) -> a > b ? a : b);
int min = intStream.reduce(Integer.MAX_VALUE, (a,b) -> a < b ? a : b);