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());
相关推荐
yujunl13 小时前
resx文件上具有 Web 标记
开发语言
catchadmin13 小时前
免费可商用 PHP 管理后台 CatchAdmin V5.3.1 发布 后台打包直降 5s 内
开发语言·php
小江的记录本13 小时前
【Spring AI】Spring AI中RAG误触发与系统提示词泄露问题解决方案(完整版+代码方案)
java·人工智能·spring boot·后端·python·spring·面试
YY&DS13 小时前
Qt Designer 自定义控件已提升后,如何修改提升类
开发语言·qt
勇往直前plus13 小时前
Python 属性访问与操作全解析:内置函数、魔法方法与描述符深度指南
java·网络·python
Arenaschi14 小时前
关于GPT的版特点
java·网络·人工智能·windows·python·gpt
人道领域14 小时前
【LeetCode刷题日记】108.将有序数组转换为二叉搜索树
java·算法·leetcode
右耳朵猫AI14 小时前
Rust技术周刊 2026年第19周
开发语言·后端·rust
橙淮14 小时前
并发编程(五)
java
Leweslyh14 小时前
基于 Confucius 架构的无人集群网络控制原语解析
开发语言·网络·php