Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The concept of Stream, the new feature of Java 8

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report