Java stream流 常用记录

根据列表中的某个字段进行去重

java 复制代码
// 根据roleKey对列表去重
            return roleList.stream()
                    .map(AccountRole::getRoleKey)
                    .distinct()
                    .map(roleKey -> roleList.stream()
                            .filter(role -> role.getRoleKey().equals(roleKey))
                            .findFirst()
                            .orElse(null))
                    .filter(Objects::nonNull)
                    .collect(Collectors.toList());
相关推荐
承渊政道14 分钟前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame
爱学习的程序媛14 分钟前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
budingxiaomoli2 小时前
Spring统一功能处理
java·后端·spring
eggwyw2 小时前
Anaconda安装卸载的详细流程指南
开发语言·python
Flynn Liang3 小时前
可观测性与成本治理:一次对话的 17 个观测点
java·langchain·可观测性·micrometer·langchain4j·token 成本·llm 监控
金銀銅鐵3 小时前
带您看懂字节码指令(三):同一行加法,为什么有四种指令
java·jvm
another heaven6 小时前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
文丑颜不良啊7 小时前
LeetCode2821~2840题目解析
java·leetcode
SomeOtherTime8 小时前
Rust 闭包语法和原理(AI回答)
开发语言·后端·rust
apcipot_rain8 小时前
C++转Java日记(10)
java·开发语言