Java8新特性
Java9新特性

Java8获取Stream流的方式

package com.wkcto.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

/**
 * 流的基本操作
 * Author : 乐学网老崔
 */
public class Test01 {
    public static void main(String[] args) {
        //1 如何获得流,可以通过Collection集合,数据, 根据字面量获得流
        //1.1 通过Collection获得流
        List list = new ArrayList<>();
        Collections.addAll(list,"wkcto","hello", "jj", "dd", "mm", "sxbdqn");
        Stream stream1 = list.stream();
//        System.out.println(stream1);
        stream1.forEach(System.out::println);

        //1.2 根据数据获得流
        String[]data = {"zhangsan","lisi","wangwu"};
        Stream stream2 = Arrays.stream(data);
        stream2.forEach(s -> System.out.print(s + "  "));
        System.out.println();

        //1.3 直接通过值获得流
        Stream stream3 = Stream.of("1", "2", "3", "4");
        stream3.forEach(s -> System.out.print(s + "  "));
        System.out.println();

        //1.4 无限流
        Stream.iterate(100, x->x+3).limit(10).forEach(s -> System.out.print(s + "  "));
        System.out.println();

    }
}


3.1.3 流的使用