Several ways to create a stream in Java8

Source: Internet
Author: User

Import Java.math.biginteger;import java.util.arraylist;import Java.util.arrays;import Java.util.List;import Java.util.regex.pattern;import java.util.stream.stream;/** * * @author Kangjun Ways of Creating a stream in Java 8 */publi        C class Streamdemo {public static void main (string[] args) {arraysstream ();        Collectionstream ();        Generate ();                Iteratestream ();    Populastream (); }//from Arrays public static void Arraysstream () {string[] arr = {' program ', ' Creek ', ' Program ', ' Creek ', '        Java "," Web "," program "};        stream<string> stream = Stream.of (arr);    System.out.println (arrays.tostring (arr)); }//from Collections public static void Collectionstream () {list<string> List = new Arraylist<> (        );        List.add ("Java");        List.add ("Python");        List.add ("C + +");        List.add ("C");        List.add ("Lisp"); stream<string> stream = List.stream (). Filter (P-P.length () > 3);        string[] arr = Stream.toarray (string[]::new);    System.out.println (arrays.tostring (arr)); }//use stream.generate () public static void Generate () {stream<string> Stream = Stream.generate (()-& Gt        "Test"). Limit (10);        string[] Strarr = Stream.toarray (string[]::new);    System.out.println (arrays.tostring (Strarr)); }//use stream.iterate () public static void Iteratestream () {stream<biginteger> Bigintstream = Stream.        Iterate (Biginteger.zero, N-n.add (Biginteger.ten)). Limit (10);        biginteger[] Bigintarr = Bigintstream.toarray (biginteger[]::new);    System.out.println (arrays.tostring (Bigintarr)); }//from Popular APIs public static void Populastream () {String sentence = "Program Creek is a Java site."        ;        stream<string> Wordstream = Pattern.compile ("\\w"). Splitasstream (sentence);        string[] Wordarr = Wordstream.toarray (string[]::new); System.out.println (Arrays.tostring (Wordarr)); }}



Several ways to create a stream in Java8

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.