DEV Community

Discussion on: The joy of streams

Collapse
 
jeyj0 profile image
Jannis Jorre

You could even replace .filter(event -> event != null) with .filter(Objects::nonNull) !

Another awesome note: when calling .parallel() on a stream, every further task in the pipeline gets executed in parallel using the default forkjoinpool, which uses exactly the number of cores available minus 1 (for the main thread). Awesome for speeding up tasks in some situations!

Collapse
 
bertilmuth profile image
Bertil Muth

You're right. I created this based on an example with deeper nesting, and kept it in as I thought it might be easier to grasp for somebody new to the topic.

Collapse
 
jeyj0 profile image
Jannis Jorre

(1) I assumed it was because of a reason like that, but still wanted to give a hint for those who might appreciate it. I'd consider it a cleaner and more readable solution.

(2) This is definitely for more advanced users, but is such a powerfull tool, that I thought it should definitely be mentioned.