stream对比两个list根据字段查询出不同得值

5 篇文章 0 订阅
5 篇文章 1 订阅

工作需要 要查出来两个list对象得差值 是根据其中一个字段的 正好这段时间再用stream 就试了一下

//需要求相同的只需要把第二行!去掉就行
 List<AlarmComparisonDto> collect = lastWeekHostAlarmNum.stream()
                .filter(item -> !thisWeekHostAlarmNum.stream()
                        .map(e -> e.getHostId())
                        .collect(toList())
                        .contains(item.getHostId()))
                .collect(toList());
        System.err.println(thisWeekHostAlarmNum+"--------thisWeekHostAlarmNum");
        System.err.println(lastWeekHostAlarmNum+"-------------lastWeekHostAlarmNum");
        System.err.println(collect+"-------------collect");

AlarmComparisonDto的也一起放出来吧

/**
 * ClassName: AlarmComparisonDto
 * Description:
 * date: 2022/1/19 10:47
 *
 * @author robotname a
 * @author dev whz
 * @since JDK 1.8
 */
@Data
public class AlarmComparisonDto {

    private Integer restNum;

    private Integer hostId;

    private boolean sort;
}

结果
在这里插入图片描述


[AlarmComparisonDto(restNum=14, hostId=10369, sort=false), AlarmComparisonDto(restNum=1, hostId=10423, sort=false), AlarmComparisonDto(restNum=2, hostId=13213, sort=true)]--------thisWeekHostAlarmNum
[AlarmComparisonDto(restNum=1, hostId=11120, sort=false), AlarmComparisonDto(restNum=1, hostId=11121, sort=false), AlarmComparisonDto(restNum=1, hostId=13213, sort=false)]-------------lastWeekHostAlarmNum
[AlarmComparisonDto(restNum=1, hostId=11120, sort=false), AlarmComparisonDto(restNum=1, hostId=11121, sort=false)]-------------collect

后记 同我们公司大哥说 这么效率比较低 还需要优化 先记录一下 优化之后再后面继续编辑

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值