zoukankan      html  css  js  c++  java
  • JDK8 Lambda

    之前看过JAVA 8的书,但由于时间长,平时没用所以忘的差不多了,大概记得格式。

    常用代码

    1.获得对象集合的某个属性倒序(最新)的一个对象

    Optional<AppLog> appPLog = appLogList.stream().sorted(Comparator.comparing(AppLog::getCreationTime).reversed()).findFirst();

    2.过滤条件的对象集合

    List<User> filterList = list.stream().filter(user -> Integer.valueOf(user.getAge()) > 60).collect(Collectors.toList());

    3.fastjson 数组去重

    JSONArray.parseArray(JSON.toJSONString(array.stream().distinct().collect(Collectors.toList())))

    4.按某一字段分组统计 

    Map<String, DoubleSummaryStatistics> staffTimeResultMap = staffTimeList.stream().collect(Collectors.groupingBy(ProjectInfo::getName, Collectors.summarizingDouble(ProjectInfo::getTimes)));

    5.按日期分组计数

    Map<String, Long> countingMap = popupClickList.stream().collect(Collectors.groupingBy(lc -> sdf.format(lc.getLog_time()), Collectors.counting()));
  • 相关阅读:
    Web Api 模型绑定 二
    C#关键字
    ASP.NET Core MVC 过滤器
    EF性能优化篇一
    Linq
    HTTP协议
    Linux进程管理(11)
    Linux网络配置(10)
    Django模板修炼
    递归
  • 原文地址:https://www.cnblogs.com/julian-chang/p/11896996.html
Copyright © 2011-2022 走看看