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
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM