How to do it...

In this section of the recipe, we will present methods to create a stream. Each class that implements the Set interface or the List interface has the stream() method and the parallelStream() method, which returns an instance of the Stream interface:

  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 ", 4, "by ", 5,                             "Map.of().entrySet().stream()")                 .entrySet().stream().forEach(System.out::print);

We used the fluent style to make the code more compact and ...

Get Java 11 Cookbook 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.