I need an efficient way of removing items from list. If some condition happens, I need to remove first ‘n’ elements from a list. Can some one suggest the best way to do this? Please keep in mind: performance is a factor for me, so I need a faster way than itterating. Thanks.
I’m thinking of a way through which the ‘n’th item can be made as the starting of the list so that the 0-n items will get garbage collected. Is it possible?
If performance is key for you, then I’m not sure using built-in functions from ArrayList is the way to go. I doubt they run faster than O(n) and sadly Java documentation says nothing about that. Maybe you should look into some custom made structures like a Rope.