April 2019
Intermediate to advanced
360 pages
9h 17m
English
The StreamExample class provided next demonstrates the streams design pattern. The class imports the Stream class, which is part of the java.util.stream package. There are three chained calls made to the peek(), limit(), and forEach() methods:
import java.util.stream.Stream;public class StreamExample { public static void main(String[] args) { System.out.println(); Stream.iterate(0, x->x+3) .peek(number -> System.out.print("\nPeeked at: ")) .limit(7) .forEach(System.out::println); }}
The output of the StreamExample class is provided here:

This section ...
Read now
Unlock full access