Java8 new Feature (Stream API)

Source: Internet
Author: User
Tags stream api

Procedure for the Stream API:

1. Create stream

2. Intermediate operation

3. Terminate operation (Terminal operation)

//1. Create Stream@Test Public voidtest1 () {//1. Collection provides two methods for stream () and Parallelstream ()list<string> list =NewArraylist<>(); Stream<String> stream = List.stream ();//gets a sequential streamstream<string> Parallelstream = List.parallelstream ();//get a parallel stream//2. Get an array stream through stream () in Arraysinteger[] Nums =Newinteger[Ten]; Stream<Integer> stream1 =Arrays.stream (nums); //3. Through the Stream class static method of the ()stream<integer> stream2 = Stream.of (1,2,3,4,5,6); //4. Create an infinite stream//Iterationstream<integer> stream3 = Stream.iterate (0, (x) x +2). Limit (Ten); Stream3.foreach (System. out::p rintln); //Buildstream<double> stream4 = stream.generate (math::random). Limit (2); Stream4.foreach (System. out::p rintln); }

Java8 new Feature (Stream API)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.