3 ms·
> That's exactly what Java thinks and thus it chose to keep the Streams lazy. Rumours of Stream's laziness have been greatly exaggerated. Stream<Integer> aS
by mrkeen 7y ago
> That's exactly what Java thinks and thus it chose to keep the Streams lazy.
Rumours of Stream's laziness have been greatly exaggerated.
Stream<Integer> aStream =
Stream.iterate(1, i -> i + 1)
.flatMap(i -> Stream.iterate(i, j -> j + 1)
.flatMap(j -> Stream.iterate(j, k -> k + 1)));
// Does not terminate
Integer firstElement = aStream.findFirst().get();