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?
create subList()
Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.
Check implementation of this method and make some tests to determine performance
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