zoukankan      html  css  js  c++  java
  • Java8 流操作

    String[] strs = {"34020000002000000001", "34020000002000000002", "34020000002000000003", "34020000002000000004"};
            List<String> collect = Arrays.stream(strs).map(a -> a.split("")).flatMap(Arrays::stream).collect(Collectors.toList());
            System.out.println(collect);
    
            List<String> collect2 = Arrays.stream(strs).map(a -> a.split("")).flatMap(Arrays::stream).distinct().collect(Collectors.toList());
            System.out.println(collect2);
    
            List<String> collect1 = Arrays.stream(strs).map(a -> a.substring(0, 4)).collect(Collectors.toList());
            System.out.println(collect1);
    
            String[] words = {"Hello", "World"};
            List<String> a = Arrays.stream(words)
                    .map(word -> word.split(""))
                    .flatMap(Arrays::stream)
                    .distinct()
                    .collect(Collectors.toList());
            System.out.println(a);
            a.forEach(System.out::print);
    

    对应的输出结果:

    [3, 4, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 4, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 4]
    [3, 4, 0, 2, 1]
    [3402, 3402, 3402, 3402]
    [H, e, l, o, W, r, d]
    HeloWrd
    
  • 相关阅读:
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    deleted
    CF #505 B Weakened Common Divisor(数论)题解
    HDU 6425 Rikka with Badminton(组合问题签到)题解
    ZOJ 2747 Paint the Wall(离散化+暴力)题解
  • 原文地址:https://www.cnblogs.com/InternetJava/p/15731301.html
Copyright © 2011-2022 走看看