Remove multiple elements from ArrayList
问题 I have a bunch of indexes and I want to remove elements at these indexes from an ArrayList . I can't do a simple sequence of remove() s because the elements are shifted after each removal. How do I solve this? 回答1: Sort the indices in descending order and then remove them one by one. If you do that, there's no way a remove will affect any indices that you later want to remove. How you sort them will depend on the collection you are using to store the indices. If it's a list, you can do this: