| Author |
performance issues with removeAll() of ArrayList
|
Peehu Singh
Greenhorn
Joined: Mar 14, 2007
Posts: 4
|
|
Just seen that removeAll() method of ArrayList() perform worse when list has over 100000 records.....It take minutes to complete. Any work around?? ....I am using JDK1.5
thanks in advance.
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3859
|
|
Hi Peehu. Welcome to The Ranch!
Can you just create a new ArrayList and throw the other one away?
|
 |
Peehu Singh
Greenhorn
Joined: Mar 14, 2007
Posts: 4
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
|
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.
|
 |
 |
|
|
subject: performance issues with removeAll() of ArrayList
|
|
|