Streams are introduced in Java 8 through a generic Class java.util.stream.Stream<T>.
Stream
● is just a wrapper around sequence of elements (Data Source)
● that allows us to make bulk processing of these elements
● and then store the results in some Data Collector.
Stream
● works as a pipe that hooks up between Data Source and Data Collector and modifies elements as they pass through
● doesn't modify the underlying Data Source (just reads elements from it)
● doesn't store data
Stream<T> uses fluent API so Methods can be called in a Sequence since every Stream Method returns a new Stream on
which next Method can be called. You can think of having one long Stream that is actually created of smaller Streams.
Every time you call a Stream Method you
● actually create a new Stream
● that feeds on the elements from the previous Stream (receives previous Stream as its input)
● performs specific modification on those elements (and creates new Stream as its Output)
Some Stream Methods accept Functions as parameters which are usually given as Lambda Expressions.
Such Handlers (they Handle Elements) might define how to modify elements that pass through the Stream.
Or they might contain logic to filter elements (disregard certain elements so that they don't reach the end of the Stream).
Stream