I have a for loop loop through ArrayList.
If the condition is satisfied in the for loop:
- I delete the current item from
ArrayList - reduce the size of a local variable
ArrayList - reduce the index of the for loop so that they never drop below zero.
The case when we just deleted the last item ArrayList:
i = (i > 0) ? i-- : i;
My problem is that the above does not reduce me by 1 for i> 0. I have used triple operators countless times, but have never seen this behavior. I tested that I really> 0, and that the i-section is being called. It just does not reduce the value of i. Removing a check of a value of 0 and simple execution i--;really reduces i as expected.
EDIT2: Well, someone edited my last edit, where I mentioned that in this case I specifically DO NOT use ListIterator due to the performance sensitivity of the loop itself, which is in the critical part of Android code.
source
share