两个list集合对象,根据某一A集合中对象id判断是否在另一个B集合对象的id中是否有重复,取A集合中有,B集合 ...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 21:04   3139   0

需要判断,并且获取对象的具体信息


one: for (int i = 0; i < A.size(); i++) {
    for (int j = 0; j < B.size(); j++) {
        if (A.get(i).getId().equals(B.get(j).getId())) {
            continue one;
        }
    }
    // A集合中,B集合没有的对象id
    System.out.println(A.get(i).getId());

}

只需要id时可用下面这种方式

                List<String> aIds = A.stream().map(A::getId).collect(Collectors.toList());
                List<String> bIds = B.stream().map(B::getId).collect(Collectors.toList());
                // 对比
                for(String id:aIds){
                    if(!bIds.contains(id)){
                        // A集合中,B集合没有的对象id
                        System.out.println(id);
                    }
                }

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP