当前位置: 首页 > news >正文

stream对list数据进行多字段去重

方法一:

//根据sj和name去重
List<NursingHandover> testList = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getj() + ";" + o.getName() + ";"))), ArrayList::new));

方法二:

// 通过Map生成键值对,Key去重
Map<Long, String> newMap = list.stream().collect(Collectors.toMap(NursingHandover::getSj, NursingHandover::getName));

方式三:

// 通过多个字段分组,并生成Map:key(字段组合),value(对象列表)
Map<Object, List<NursingHandover>> costLmmMap = list.parallelStream().collect(Collectors.groupingBy(item -> (item.getSj() +"_" + item.getName()), Collectors.toList()));
http://www.lryc.cn/news/180783.html

相关文章:

  • 一种基于体素的射线检测
  • 利用Docker安装Protostar
  • go基础语法10问
  • SpringCloud + SpringGateway 解决Get请求传参为特殊字符导致400无法通过网关转发的问题
  • vim基本操作
  • Drift plus penalty 漂移加惩罚Part1——介绍和工作原理
  • (四)动态阈值分割
  • jvm介绍
  • 数据结构与算法课后题-第三章(顺序队和链队)
  • SSM - Springboot - MyBatis-Plus 全栈体系(十六)
  • k8s--storageClass自动创建PV
  • 7.3 调用函数
  • 如果使用pprof来进行性能的观测和优化
  • 在移动固态硬盘上安装Ubuntu系统和ROS2
  • 【iptables 实战】02 iptables常用命令
  • webview_flutter
  • 【GESP考级C++】1级样题 闰年统计
  • CentOS密码重置
  • Tomcat Servlet
  • 国庆day2---select实现服务器并发
  • Grafana 开源了一款 eBPF 采集器 Beyla
  • 亲测可用国产GPT人工智能
  • 适配器模式详解和实现(设计模式 四)
  • IDEA的使用
  • CSS详细基础(二)文本样式
  • win10系统任务栏图标变成白色的解决办法
  • hadoop生态现状、介绍、部署
  • 二、EFCore 数据库表的创建和迁移
  • 在nodejs中使用typescript
  • 数据结构与算法基础(青岛大学-王卓)(8)