美文网首页
Java8 Stream

Java8 Stream

作者: 咖啡机an | 来源:发表于2022-12-01 15:10 被阅读0次

    1. string->int排序

    resultList = totalList.stream().sorted(Comparator.comparing(s::getFinishRate, Comparator.comparingInt(Integer::parseInt)).reversed()).collect(toList());
    

    2.List->Map

    #值为对象中的字段
    Map<String, String> Map = totalList.stream().collect(Collectors.toMap(s::getOrgId, s::getGridCount, (v1, v2) -> v2));
    #值为对象本身
    Map<String, WgrbStatistic> map = wgList.stream().collect(Collectors.toMap(WgrbStatistic::getOrgId, item->item));
    

    3.List-> Sum

    String count = String.valueOf(resultList.stream().map(s::getCountFinish).mapToInt(Integer::parseInt).sum());
    

    相关文章

      网友评论

          本文标题:Java8 Stream

          本文链接:https://www.haomeiwen.com/subject/niwefdtx.html