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()));
  • 相关阅读:
    5,7地面物品
    0,1选怪
    0,2使用红,蓝
    BT地址(__)
    3,7包裹物品数组
    0,4捡物
    如何在目标内网中发现更多存活主机
    xss自动化攻击
    .NET Framework 4安装失败
    利用struts1.x框架需要注意的问题
  • 原文地址:https://www.cnblogs.com/julian-chang/p/11896996.html
Copyright © 2011-2022 走看看