Can you just create a new ArrayList and throw the other one away?
Joined: Mar 14, 2007
I have requirement as mentioned below:
1. have two lists which has more then 500000 items, say list1 has 10,00000 items whereas list2 has 600000 items out of which 400000 items are redundent (also present in list1). Now I want a list which has unique items i.e. list1 - list2.
The removeAll method is described in AbstractCollection. It doesn't say what complexity it has, but it would appear to be quadratic, well O(n1 * n2). How about copying the second List into a HashSet? Its contains() method should run in constant time, then you can convert the method to linear time.