list求差集的方法汇总(两个不同元素的List集合)

一个全部用户集合List< UserInfo > allUser,一个部分用户集合List< UserInfo > commentUser,

根据UserInfo中的UserID求差集,从allUser中得到剩下的一部分用户,通过stream流和lamda表达式实现

public List<UserInfo> getNotComment(List<UserInfo> allUser,List<UserInfo> commentUser){
    List<UserInfo> notCommentUser = allUser.stream()
             .filter(notComment -> !commentUser.stream().map(all -> all.getUserId()).collect(Collectors.toList()).contains(notComment.getUserId()))
             .collect(Collectors.toList());
    return notCommentUser;
}

 

posted @   郭慕荣  阅读(63)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
历史上的今天:
2022-11-28 Java8 Function 用法简介
2022-11-28 mysql联合更新
点击右上角即可分享
微信分享提示