Reputation: 157
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.
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.
Upvotes: 2
Views: 1003
Reputation: 10695
Use HashSet
collection
List<MyClass> myList = new ArrayList<MyClass>();
myList.addAll(listA);
myList.addAll(listB);
Set<MyClass> mySet = new HashSet<MyClass>(myList);
Upvotes: 3