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

How to do it...

In this section of the recipe, we will present methods of stream creation. As mentioned in the introduction, each class that implements the Set interface or the List interface has the stream() method and the parallelStream() method that return an instance of the Stream interface. For now, we will only look at sequential streams created by the stream() method and get back to parallel streams later.

  1. Consider the following examples of stream creation:
        List.of("This", "is", "created", "by", "List.of().stream()")            .stream().forEach(System.out::print);        System.out.println();        Set.of("This", "is", "created", "by", "Set.of().stream()")           .stream().forEach(System.out::print);        System.out.println(); Map.of(1, "This ", 2, "is ", 3, "built ...

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