比较两个LIST直接的差异

qingtingnayongheng 2015-09-24 09:36:24
现在我有两个List:
1.List<AccountDtoVo> paList ={[custCode=pxx1,act=2],[custCode=pxx2,act=5],[custCode=pxx3,act=12]}
2.List<AccountDtoVo> lihsList ={[custCode=pxx1,act=2],[custCode=pxx2,act=3],[custCode=pxx4,act=8]}

比较两个List以paList 为主,我想获得的结果是
{[custCode=pxx2,act=5],[custCode=pxx3,act=12]}

请帮忙用尽量用高效的代码,因为两个LIST 数据量很大
...全文
774 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
suciver 2015-09-25
  • 打赏
  • 举报
回复
写好AccountDtoVo的hashCode和equals方法,直接用paList.removeAll(lihsList);
铁匠梁老师 2015-09-25
  • 打赏
  • 举报
回复
活到老学到老
tony4geek 2015-09-24
  • 打赏
  • 举报
回复
apache 的CollectionUtils api
tony4geek 2015-09-24
  • 打赏
  • 举报
回复
CollectionUtils 例1: 判断集合是否为空: CollectionUtils.isEmpty(null): true CollectionUtils.isEmpty(new ArrayList()): true CollectionUtils.isEmpty({a,b}): false 例2: 判断集合是否不为空: CollectionUtils.isNotEmpty(null): false CollectionUtils.isNotEmpty(new ArrayList()): false CollectionUtils.isNotEmpty({a,b}): true 2个集合间的操作: 集合a: {1,2,3,3,4,5} 集合b: {3,4,4,5,6,7} CollectionUtils.union(a, b)(并集): {1,2,3,3,4,4,5,6,7} CollectionUtils.intersection(a, b)(交集): {3,4,5} CollectionUtils.disjunction(a, b)(交集的补集): {1,2,3,4,6,7} CollectionUtils.disjunction(b, a)(交集的补集): {1,2,3,4,6,7} CollectionUtils.subtract(a, b)(A与B的差): {1,2,3} CollectionUtils.subtract(b, a)(B与A的差): {4,6,7}
少主无翼 2015-09-24
  • 打赏
  • 举报
回复
JDK自带的removeAll()方法效率应该不低,建议使用
解开者 2015-09-24
  • 打赏
  • 举报
回复
AccountDtoVo类提供equals实现,然后调用paList.removeAll(lihsList)。为了提高效率应该改用Iterator支持remove操作的集合并且remove操作的效率应该尽量高
qingtingnayongheng 2015-09-24
  • 打赏
  • 举报
回复
引用 楼主 qingtingnayongheng 的回复:
现在我有两个List: 1.List<AccountDtoVo> paList ={[custCode=pxx1,act=2],[custCode=pxx2,act=5],[custCode=pxx3,act=12]} 2.List<AccountDtoVo> lihsList ={[custCode=pxx1,act=2],[custCode=pxx2,act=3],[custCode=pxx4,act=8]} 比较两个List以paList 为主,我想获得的结果是 {[custCode=pxx2,act=5],[custCode=pxx3,act=12]} 请帮忙用尽量用高效的代码,因为两个LIST 数据量很大
我用containsAll这方法实现不了,还有什么其他方法吗? 难道就真的只能用无脑FOR循环?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧