Optimization ArrayList.removeAll

Many said that ArrayList.removeAll very slow with large arrays.

This article provides two optimized solutions for the speed of ArrayList.removeAll, but it requires their implementation in the class itself and cannot be used externally as a fix.

Is there a way to apply this type of fix that does not copy the source code of ArrayList and uses my own version?

Edit: I suppose I should add my need for this, since there is probably a way to do what I want without ArrayList.removeAll.

I have two lists around 70,000 longs each. They are almost identical, but in one list there are several more numbers that the second list does not have, and I want to find them. The only way to find them is to do first.removeAll(second) to find the difference. Is there another way?

+8
java arraylist
source share
2 answers

How about using a data structure that has a much better deletion time like a HashSet or TreeSet? Therefore, the big reason to use arraylist is due to the fast O (1) access time for accessing records. But if you are trying to make a difference, perhaps you should use sets. Just a thought.

+9
source share

You can subclass ArrayList to optimize this method (and possibly others).

+1
source share

All Articles