September 2019
Intermediate to advanced
816 pages
18h 47m
English
In the first part of this problem, we will talk about infinite streams. In the second part, we will talk about the takeWhile() and dropWhile() APIs.
An infinite stream is a stream that creates data indefinitely. Because streams are lazy, they can be infinite. More precisely, creating an infinite stream is accomplished as an intermediate operation, and so no data is created until a terminal operation of the pipeline is executed.
For example, the following code will theoretically run forever. This behavior is triggered by the forEach() terminal operation and caused by a missing constraint or limitation:
Stream.iterate(1, i -> i + 1) .forEach(System.out::println);
The Java Stream API allows ...