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 convert the elements of the stream using an intermediate operation and an expression that makes the conversion between the source and the destination types. We used three different methods in our example:

  • mapToDouble(): We used this method to convert Stream of objects into DoubleStream with double numbers as elements. This method receives as parameter a lambda expression or an implementation of the ToDoubleFunction interface. This expression receives an element of Stream and has to return a double value.
  • map(): We can use this method when we have to convert the elements of Stream to a different class. For example, in our case, we convert the Person class to a BasicPerson class. This method ...

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