File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes performance issues with removeAll() of ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "performance issues with removeAll() of ArrayList" Watch "performance issues with removeAll() of ArrayList" New topic
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
    
    1

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
    
    4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: performance issues with removeAll() of ArrayList
 
Similar Threads
Comparing Two ArrayLists Objects
Polymorpic Doubt
How to remove common item between 2 ArrayList
Remove a subset of objects at once
how to remove object of perticular class from ArrayList..?