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