I'm writing an article about the Java Stream API. I've read the whole package documentation for Stream, and I've looked through similar questions here.
If I said the following: "Intermediate operations on a stream are not evaluated until the terminal operation is hit, which will actually perform them," would I be correct? I've seen mixed answers on StackOverflow, and also each intermediate operation returns a Stream, so I was wondering if it just returned itself and then just kept track of the the intermediate operations to perform as it went along. Is this what is meant by "lazy evaluation/execution"?
the following javadoc is giving me mixed signals honestly.. maybe I'm just stupid
Intermediate operations return a new stream. They are always lazy; executing an intermediate operation such as filter() does not actually perform any filtering, but instead creates a new stream that, when traversed, contains the elements of the initial stream that match the given predicate. Traversal of the pipeline source does not begin until the terminal operation of the pipeline is executed.
Thanks so much for your time! Sorry if I'm missing something ;( I've been stuck on this for a long time!
P.S: Stream and lazy evaluation is very similar, but "Each intermediate operation creates a new stream, stores the provided operation/function and return the new stream." So basically, my question is, by new stream, does it mean the same stream that it was given?