java流式编程的流的生成方式

流:

  1. 集合流
  2. Map流
  3. 数组流

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

//几种流的生成方式
public class StreamDemo2 {
    public static void main(String[] args) {
        //Collections生成流
        ArrayList<String> strings = new ArrayList<>();
        Stream<String> stream = strings.stream();

        //map的流
        Map<Integer, Integer> integerIntegerMap = new HashMap<>();
        //键的流
        Stream<Integer> stream1 = integerIntegerMap.keySet().stream();
        //值得流
        Stream<Integer> stream2 = integerIntegerMap.values().stream();
        //键值对得流
        Stream<Map.Entry<Integer, Integer>> stream3 = integerIntegerMap.entrySet().stream();

        //数组得流
        int[] a = {1,2,3,4,5,6,7};
        Stream<int[]> a1 = Stream.of(a);
    }
}


posted @ 2021-05-03 18:23  code-G  阅读(143)  评论(0编辑  收藏  举报