Java8 Stream
// 1、排除空串 List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl"); List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList()); // 2、forEach filtered.forEach(s -> System.out.println(s)); // ==>filtered.forEach(System.out::println); // 3、map List<String> testMap = filtered.stream().map(s -> s + s).collect(Collectors.toList()); // 4、filter Long count = strings.stream().filter(s -> s.isEmpty()).count(); System.out.println("空串的数量为:count = " + count); // 5、limit filtered.stream().limit(2).forEach(System.out::println); // 6、sorted System.out.print("6 ==>"); filtered.stream().sorted(Comparator.comparing(String::toString).reversed()).forEach(System.out::println); System.out.print("7 ==>"); // 7、Collectors String mergeString = filtered.parallelStream().collect(Collectors.joining(",")); System.out.println(mergeString); //8 、 mapToInt OptionalInt max = filtered.stream().mapToInt(s -> Integer.parseInt(s)).max();