CH10 - Streams Flashcards
(7 cards)
Stream
A stream in Java is a sequence of data.
A stream pipeline consists of the operations that run on a stream to produce a result.
With streams, the data isn’t generated up front - it is created when needed.
This is an example of lazy evaluation, which delays execution until necessary.
Source
Where the stream comes from
Intermediate operations
Transforms the stream into another one.
There can be as few or as many intermediate operations
Since streams use lazy evaluation, the intermediate oeprations do not run until the terminal operation runs.
Required part - No
Exist multiple time - Yes
Return stream type - Yes
Executed upon method call - No
Stream valid after call - Yes
Terminal operation
Produces result.
Streams are not valid after terminal operation completes.
Required part - Yes
Exist multiple time - No
Return stream type - No
Executed upon method call - Yes
Stream valid after call - No
Stream.iterate(seed, unaryOperator)
Creates Stream by using seed for first element and then calling UnartOperator for each subsequent element upon request
Stream.iterate(seed, predicate, unaryOperator)
Creates Stream by using seed for first element and then calling UnaryOperator for each subsequent element upon request. Stops if Predicate returns false.