I have an ArrayList that I loop and through some logic I would remove an element at a particular index.
However while I am looping the Arraylist and removing on the way, the ArrayList size and index of particular items are changing as well, resulting in unexpected results.
Anyway to circumvent this?
Here’s the code for the iterator approach – substitute your own condition and add generics types <> as needed:
And, as JohnB said in the comments, ArrayList isn’t very efficient if you are removing lots of items from large lists…