O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

In this recipe you learnt how to use three methods to process all the elements of a stream and apply an action to them. These methods are:

  • forEach(): This is a terminal operation that applies an action to all the elements of Stream and returns a void value. It receives as parameter the action to apply to the elements defined as a lambda expression or as an implementation of the Consumer interface. There's no guarantee about the order in which the action will be applied to the elements of a parallel stream.
  • forEachOrdered(): This is a terminal operation that applies an action to all the elements of Stream in the order of the stream, if the stream is an ordered stream, and returns a void value. You can use this method after ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required