Stream

 

public static void main(String[] args) {
        //Stream(流)是一个来自数据源的元素队列并支持聚合操作
        //聚合操作:类似SQL语句一样的操作, 比如filter, map, reduce, find, match, sorted等。
        Random random = new Random();
        random.ints().limit(3).forEach(System.out::println);

        final Stream<String> stream = Stream.of("Red", "Blue", "Green");
        stream.forEach(System.out::println);

        IntStream intStream = IntStream.of(10, 20, 30);
        intStream.forEach(System.out::println);

        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "");
        Stream<String> countStream = strings.stream().filter(string -> string.isEmpty());
        long count = countStream.count();
        System.out.println("count:" + count);

        final Stream<String> sortStream = Stream.of("Red", "Blue", "Green");
        sortStream.sorted().forEach(System.out::println);


        Integer fst = 127;
        Integer snd = new Integer(127);
        System.out.println(fst == snd); //false
        System.out.println(new Integer(127) == snd); //false
        System.out.println(fst == Integer.valueOf(127));//true
        Integer trd = 128;
        System.out.println(trd == Integer.valueOf(128)); //false
    }

 

posted @ 2021-09-01 11:17  牧 天  阅读(1015)  评论(0)    收藏  举报