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 ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.