将同一个list对象中具有相同属性的对象放入到一个新的list中

/**
     * 获取重复的元素值
     *
     * @param projectLandVos 项目片块数据集合
     * @return List<List < ProjectLandVo>> 返回重复的项目片块数据
     */
    private static List<List<ProjectLandVo>> getDuplicateElements(List<ProjectLandVo> projectLandVos) {
        //用于接收重复的项目片块数据,返回给方法的调用者
        List<List<ProjectLandVo>> result = new ArrayList<List<ProjectLandVo>>();
        //用于临时保存重复的项目片块数据
        Map<String, List<ProjectLandVo>> map = new TreeMap<String, List<ProjectLandVo>>();

        for (ProjectLandVo bean : projectLandVos) {
            //判断当前值是否已经在map中存在
            if (map.containsKey(bean.getLandNum())) {
                List<ProjectLandVo> hasObj = map.get(bean.getLandNum());
                //对象拷贝
                ProjectLandVo landTarget = new ProjectLandVo();
                BeanUtil.copyProperties(bean, landTarget);
                hasObj.add(landTarget);
                new ArrayList<ProjectLandVo>().add(landTarget);
                map.put(bean.getLandNum(), hasObj);
            } else {
                List<ProjectLandVo> newObj = new ArrayList<ProjectLandVo>();
                ProjectLandVo landTarget = new ProjectLandVo();
                BeanUtil.copyProperties(bean, landTarget);
                newObj.add(landTarget);
                map.put(bean.getLandNum(), newObj);
            }
        }
        //取出所有的重复的数据值,存入到result中
        for (Map.Entry<String, List<ProjectLandVo>> entry : map.entrySet()) {
            result.add(entry.getValue());
        }
        return result;
    }

转载地址:https://blog.csdn.net/u011277745/article/details/78860601

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值