A lot of people have said that ArrayList.removeAll
is really slow with large size arrays.
This article provides two optimized solutions to the ArrayList.removeAll speed, but requires implementing them in the class itself, and cannot be used externally as a fix.
Is there any way to apply this sort of fix short of copying the ArrayList source code and using my own version of it?
Edit: I suppose I should add my need for this, as there is probably a way to do what I want without ArrayList.removeAll.
I have two lists of around 70,000 longs
each. They are almost identical, but one list has a few more numbers that the second list doesn't have, and I want to find them. The only way I know to find them is to do first.removeAll(second)
to find the difference. Is there another way?
What about using a data structure that has a much better removal time, such as HashSet or TreeSet? So the big reason to use an arraylist is due to the fast access time O(1) to access records. But if you are trying to set difference then maybe you should use sets. Just a thought.
You can create a subclass of ArrayList
to optimize that method (and possibly others).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With