O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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

Getting ready

There are many ways to create a stream. Since Java 8, the Collection interface has the stream() method that returns a sequential stream with this collection as its source and the parallelStream() method that returns a possibly parallel stream with this collection as its source. This means that all the subinterfaces, including Set and List, also have these methods. Also, eight overloaded stream() methods were added to the Arrays class that created streams of different types from a corresponding array or subset.

The Stream interface has the of(), generate(), and iterate() methods. The specialized interfaces IntStream, DoubleStream, and LongStream have similar methods too, while IntStream also has the range() and rangeClosed() ...

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