Creating a new one will work if you did not pass it as a parameter to the method, in which case you need to change the reference object, since the new link will not be visible by the calling method.
So, if that is the case, do it in the opposite direction, this way you will not get your iterator exceeding the bounds:
int startingLength = someJsonArray.length(); for (int i = startingLength - 1; i >= 0; i--) { someJsonArray.remove(i); }
Timothy barrett
source share