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

Let's see in detail all the methods we used in this example to create streams:

  • First, we used the parallelStream() method of the List class. In fact, this method is defined in the Collection interface, so all the classes that implement this interface, such as the ArrayList, LinkedList, or TreeSet classes implement that method. You can use the stream() method to create a sequential stream or the parallelStream() method to create a parallel one.
  • Then, we used an implementation of the Supplier interface: the MySupplier class. The interface provides the get() method. This method is called each time the stream needs an element to process. You can create a stream with an infinite number of elements, so you should use a method that ...

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