Java: Removing elements from multiple indexes in a list

Use List.remove(int) on indexes in descending order:

Java 8

indexes.sort(Comparator.reverseOrder());
indexes.stream().mapToInt(i -> i).forEach(list::remove);

Java 7

Collections.sort(indexes, Collections.reverseOrder());
for (int i : indexes)
    list.remove(i);

See also Removing a range of elements from a list

Comments

Be the first to comment!