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