Stream if LAMBDA is an improved syntax for Java, then stream is an improvement on the collection of Java containers.
Stream Stream is an abstraction of a sequence of values that is located under the Java.util.stream package, which represents a series of values that have some of the same characteristics as the Java collection container, but they are fundamentally different. A collection container is a view that stores values, and a stream is a value, and it does not store values, which are a set of mirrors of values.
The set is finite, and the stream can be finite or infinite.
Streams provide many convenient aggregation operations and may be clustered in parallel, with higher performance in some cases than the collection container.
You can see that for a collection List, it can get its own stream view by calling its own stream method, and then it can be clustered on the stream view. And here we can also see through the code that using LAMBDA after combining the Stream for the collection container operation to a certain extent can be more concise and elegant, here with a line of code to print out all the more than 10 even.
For most Java collection frameworks, there is a stream method to get their own stream views, and for arrays, the Arrays tool class also provides a way to get their flow views.
And once we get a flow view, it means that we can fully manipulate the flow view using functional programming, while most operations on the flow will return a stream, and some operations will be the end operation, which returns a final result.
We can see that as long as we use the flow view and the method reference reasonably, our code will become more simple and elegant.
The mapping operation is a more interesting operation in the Stream.
Map maps can be used to map a one-way convection, and the results are simple enough to say.
And for the flow, the embedded method is very much, basically can meet most of our needs, in conjunction with LAMBDA expression is more powerful. And for the rest of the Stream Api we are not here to analyze, you can view the API documentation yourself.
Collect the previous section we simply discussed how to get a stream, and we said that a stream is actually a value mirror, and when we do the filtering sort, we naturally need to store the result, so here is a process of collecting the stream.
The process of collecting a stream is simple, and the stream provides an end operation Collect, which collects the stream according to a Collector within it, and the collectors class provides a lot of inline Collector implementations, which we can simply use.
and groupingby/mapping and so are very interesting collector implementation, you can choose your favorite collectors according to their preferences.
Parallelstream Parallelstream is the sibling function of stream, which returns a parallel stream, unlike a serial stream, which supports parallel operations, but this requires implementation support, but is actually slower than using a serial stream for testing the parallel stream, which may be my posture is wrong , the parallel flow is no longer discussed in depth, it is used in the same way as the serial stream.
Infinite flow Most of the time we use finite flow to complete the operation, but sometimes we need to use the infinite stream, for example, to ask for 30 complete number starting from 1, it can be abstracted into an infinite flow operation completely.
The stream itself also has several ways to generate the stream.
This is the end of the series.
From for notes (Wiz)
OTHER-07-LAMBDA Study notes-LAMBDA