Is the output of filter() on a Java parallel stream also parallel? (chaining filters, executed in parallel)

125 Views Asked by At

The following code applies a chain of filters to a Stream and then counts the number of resulting items:

public int countNumberOfFailedStudentsUnder20(
            final Student[] studentArray) {
        return (int) Stream.of(studentArray)
              .parallel()
              .filter(s -> !s.checkIsCurrent())
              .parallel()
              .filter(s -> s.getAge() > 20)
              .parallel()
              .filter(s -> s.getGrade() < 65)
              .count();
    }

Is the output of each subsequent filter a parallel stream (while the initial stream was made parallel by calling parallel()) or it must be converted to a parallel stream explicitly, like it presently is.

0

There are 0 best solutions below