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
    
  • 相关阅读:
    sprintf的用法
    sscanf
    Decode the tape
    poj 1579 Function Run Fun
    Where's Waldorf?
    uva Andy's First Dictionary
    UVA Hangman Judge
    UVa Automatic Editing
    界面设计规范
    web标准下的web开发流程思考
  • 原文地址:https://www.cnblogs.com/InternetJava/p/15731301.html
Copyright © 2011-2022 走看看