5. Java 8: Parallel Stream Flashcards
1
Q
Given a Collection how can one make a parallel stream?
A
Collection.parallelStream();
2
Q
Given a Stream how can one transform it into a parallel stream and back to a regular stream again.
A
stream.parallel()
.sequential();
3
Q
How can you use the reduce function of a Stream to sum all the integers of this Integer stream?
A
Stream stream = Stream.of(1, 2, 3);
Integer sum = stream.reduce(0, Integer::sum);