/**
* 获取重复的元素值
*
* @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