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());
相关推荐
Chester_19991 小时前
CSP202203C.计算资源调度器
开发语言·数据结构·c++·蓝桥杯
EXI-小洲3 小时前
Java 操作 Word:字符串替换、图片插入、动态生成表格与API接口下载
java·开发语言·spring boot·word
会周易的程序员3 小时前
给 PLC 写一个字节码虚拟机:STVM 虚拟机架构设计
开发语言·c++·虚拟机·软plc·iec61131·stvm
机器视觉知识推荐、就业指导3 小时前
为什么老说“纯 Qt 没啥就业市场”?
开发语言·qt
telepan3 小时前
Qt 开发避坑与性能指南:如何优雅、安全地定义全局常量字符串?
开发语言·qt
m0_695251493 小时前
Qt MaintenanceTool 使用国内镜像加速下载(超详细教程)
开发语言·qt
2601_961901704 小时前
SpringBoot使用Nacos进行application.yml配置管理
java·spring boot·spring
何以解忧,唯有..4 小时前
LangChain 工具调用(Tool Calling)实战指南
java·前端·langchain
大衛說4 小时前
《Python 从入门到精通》系列总览与学习路线
开发语言·python·学习
QQ_21696290965 小时前
【源码编号:project79475】SpringBoot校内二手交易平台:商品发布、分类检索、留言交流、订单管理全流程实战
java·spring boot·后端