How it works...

In this recipe, we implemented two different versions of the same algorithm to obtain Map from List. If you execute it, you will obtain the same results and a similar execution time (at least the latter is true in my case when I executed the example in a four core computer). The biggest advantage we obtained using streams is the simplicity of the solution and its development time. With only one line of code, we implemented the solution. While in the other case, we implemented a new class (the PersonMapTask) using concurrent data structures and then executed it in the fork/join framework.

With Streams, you can divide your algorithm into simple steps that can be expressed in an elegant way, be easy to program and understand. ...

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.