Java List Remove removeAll(List list, List indexes)

Here you can find the source of removeAll(List list, List indexes)

Description

Removes from the given list the elements at the given indexes.

License

Open Source License

Parameter

Parameter Description
list the list to remove elements from.
indexes the indexes for the elements to remove.

Declaration

public static <T> void removeAll(List<T> list, List<Integer> indexes) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;
import java.util.Arrays;

import java.util.Collections;

import java.util.List;

public class Main {
    /**/*from ww  w.j a  v a  2 s  .co  m*/
     * Removes from the given list the elements at the given indexes.
     * 
     * @param list the list to remove elements from.
     * @param indexes the indexes for the elements to remove.
     */
    public static <T> void removeAll(List<T> list, List<Integer> indexes) {
        if (list == null || indexes == null) {
            return;
        }

        Collections.sort(indexes, Collections.reverseOrder());

        for (Integer index : indexes) {
            list.remove((int) index);
        }
    }

    /**
     * Removes from the given list the elements at the given indexes.
     * 
     * @param indexes the list to remove elements from.
     * @param indexes the indexes for the elements to remove.
     */
    public static <T> void removeAll(List<T> list, Integer... indexes) {
        List<Integer> inx = new ArrayList<Integer>(Arrays.asList(indexes));

        removeAll(list, inx);
    }
}

Related

  1. removeAfter(List children, int index)
  2. removeAll(List list, Object[] elements)
  3. removeAll(List list, List objects)
  4. removeAll(List idxs, List values)
  5. removeAll(List strings, String string)
  6. removeAll(List toRemoveFrom, Collection elementsToRemove)
  7. removeAllNull(List list)
  8. removeAllNulls(List list)
  9. removeBlankLine(List lines)