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 数据量很大
7 个解决方案
#1
我用containsAll这方法实现不了,还有什么其他方法吗? 难道就真的只能用无脑FOR循环?
#2
AccountDtoVo类提供equals实现,然后调用paList.removeAll(lihsList)。为了提高效率应该改用Iterator支持remove操作的集合并且remove操作的效率应该尽量高
#3
JDK自带的removeAll()方法效率应该不低,建议使用
#4
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}
例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}
#6
活到老学到老
#7
写好AccountDtoVo的hashCode和equals方法,直接用paList.removeAll(lihsList);
#1
我用containsAll这方法实现不了,还有什么其他方法吗? 难道就真的只能用无脑FOR循环?
#2
AccountDtoVo类提供equals实现,然后调用paList.removeAll(lihsList)。为了提高效率应该改用Iterator支持remove操作的集合并且remove操作的效率应该尽量高
#3
JDK自带的removeAll()方法效率应该不低,建议使用
#4
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}
例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}
#5
apache 的CollectionUtils
api
#6
活到老学到老
#7
写好AccountDtoVo的hashCode和equals方法,直接用paList.removeAll(lihsList);