Java Reference
In-Depth Information
We've described the conceptual differences between collections and streams. Specifically,
streams make use of internal iteration: iteration is taken care of for you. But this is useful only if
you have a list of predefined operations to work with (for example, filter or map) that hide the
iteration. Most of these operations take lambda expressions as arguments so you can
parameterize their behavior as we showed in the previous chapter. The Java language designers
shipped the Streams API with an extensive list of operations you can use to express complicated
data processing queries. We'll briefly look at this list of operations now and explore them in
more detail with examples in the next chapter.
4.4. Stream operations
The Stream interface in java.util.stream.Stream defines many operations. They can be classified
into two categories. Let's look at our previous example once again:
You can see two groups of operations:
filter , map , and limit can be connected together to form a pipeline.
collect causes the pipeline to be executed and closes it.
Stream operations that can be connected are called intermediate operations , and operations
that close a stream are called terminal operations . Figure 4.5 highlights these two groups. So
why is the distinction important?
 
Search WWH ::




Custom Search