Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The concept of Stream, the new feature of Java 8

Shulou Source: shulou.com Published: 2022-06-02 04:02:44 10月04日 Update

This article focuses on "the concept of Stream, the new feature of Java 8". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the concept of Stream, the new feature of Java 8.

What is Stream and what is Stream?

Is a data channel for manipulating the sequence of elements generated by data sources (collections, arrays, and so on). "Collections are about data, and streams are about computing!"

Note:

① Stream does not store elements itself.

② Stream does not change the source object. Instead, they return a new Stream that holds the results.

The ③ Stream operation is deferred. This means that they will wait until the results are needed.

The operation of Stream has three steps.

① creates Stream a data source (such as collection, array) to get a stream

② intermediate operation is an intermediate operation chain to process the data of the data source.

③ termination operation (terminal operation) A termination operation that executes an intermediate operation chain and produces a result

Create Stream

The Collection interface in Java8 is extended to provide two ways to get the stream:

① default Stream stream (): returns a sequential stream

② default Stream parallelStream (): returns a parallel flow

Create a flow from an array

The static method stream () of Arrays in Java8 can get the array flow:

1 static Stream stream (T [] array): returns a stream overloaded form that can handle arrays of corresponding basic types:

2 public static IntStream stream (int [] array)

3 public static LongStream stream (long [] array)

4 public static DoubleStream stream (double [] array)

At this point, I believe you have a deeper understanding of the concept of "Java 8 new feature Stream". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Data array concept property data source method result element content processing learning practical deeper three two interest practicality actual object sequence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Apple OPPO Reno Redmi