java - Need to Remove From List at Specified Multiple Indices, without new-size problems -
this question has answer here:
- remove multiple elements arraylist 16 answers
i have array of indices @ elements must removed list, e.g.: (4), (7), (8).
the problem is:
1) can't use for-loop, size changes after each delete (arraylist.remove(i))
2) can't use iterator updated counter, counter not work anymore (iterator.remove()).
found nice solution here: remove multiple elements arraylist
collections.sort(indices, collections.reverseorder()); (int : indices) strs.remove(i); that seems fast , simple solution. reverse-sort first, go through indices , remove.
Comments
Post a Comment