• 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();
  • 相关阅读:
    javaTemplates-学习笔记三
    索引
    WTForms
    session权限限制
    vue-cli脚手架项目中组件的使用
    vue补充
    表单输入绑定
    vue指令系统介绍
    vue-cli脚手架安装和webpack-simple模板项目生成
    rest-framework之视图
  • 原文地址:https://www.cnblogs.com/hansc-blog/p/10653273.html
Copyright © 2020-2023  润新知