[英]How to compare two large array lists efficient in java
so I have 2 large arraylists of objects of A 500k and B 900k in size and I want to create a 3rd list (c) of all the dups of A in B. 所以我有2个大数组对象,分别是大小为A 500k和B 900k的对象,我想为B中所有A的重复项创建第三个列表(c)。
So I've been doing 所以我一直在做
for(obj as:B)
{
if(!A.contains(as.getA()))
{
C.add(as);
}
}
But this takes quite a bit of time to process. 但这需要花费很多时间。 Would maps or sets be quicker or any other suggestions? 地图或集合会更快或更其他建议吗? Thanks. 谢谢。
Use HashSet
collection 使用HashSet
集合
List<MyClass> myList = new ArrayList<MyClass>();
myList.addAll(listA);
myList.addAll(listB);
Set<MyClass> mySet = new HashSet<MyClass>(myList);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.