Stream流的常见生成方式

package LambdaTest.LambdaTest06;

import java.util.*;
import java.util.stream.Stream;

/**
 * FileName: StreamDemo01
 * Author:   lps
 * Date:     2022/4/10 0:22
 * Sign:刘品水 Q:1944900433
 * 生成流  中间操作 终结操作
 * Stream流的常见生成方式
 */
public class StreamDemo01 {
    public static void main(String[] args) {
        //Collection体系的集合使用默认生成;
        List<Object> list = new ArrayList<>();
        Stream<Object> liststream = list.stream();

        Set<String> hs = new HashSet<>();
        Stream<String> setstream = hs.stream();


        //Map集合间接生成流
        Map<String, Integer> map = new HashMap<>();
        Stream<String> mapstream0 = map.keySet().stream();

        Stream<Integer> mapstream1 = map.values().stream();

        Stream<Map.Entry<String, Integer>> mapstream2 = map.entrySet().stream();


        //数组通过Stream接口的静态方法of(T...values)生成流
        String[] strs={"lps","Java","yyds"};
        Stream<String> stringStream = Stream.of(strs);
        Stream<String> stringStream1 = Stream.of("lps","world","java");
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4);


    }
}

 

posted @ 2022-04-10 11:19  刘品水  阅读(77)  评论(0编辑  收藏  举报