java - Remove multiple elements from ArrayList -
i have bunch of indexes , want remove elements @ these indexes arraylist
. can't simple sequence of remove()
s because elements shifted after each removal. how solve this?
sort indices in descending order , remove them 1 one. if that, there's no way remove affect indices later want remove.
how sort them depend on collection using store indices. if it's list, can this:
list<integer> indices; collections.sort(indices, new comparator<integer>() { public int compare(integer a, integer b) { //todo: handle null return b.compareto(a); } }
edit
@aioobe found helper failed find. instead of above, can use
collections.sort(indices, collections.reverseorder());
Comments
Post a Comment