• Post Reply Bookmark Topic Watch Topic
  • New Topic

performance issues with removeAll() of ArrayList  RSS feed

 
Peehu Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peehu. Welcome to The Ranch!

Can you just create a new ArrayList and throw the other one away?
 
Peehu Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56529
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!