Java List Remove removeAll(List list, List objects)

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

Description

Removes all objects from list.

License

Open Source License

Parameter

Parameter Description
E the element type of the list
list the list
objects a list of objects to be removed from list

Declaration

public static <E> void removeAll(List<E> list, List<? extends E> objects) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;
import java.util.List;

public class Main {
    /**/*from w  w  w. j ava  2 s.  c om*/
     * Removes all <code>objects</code> from <code>list</code>.
     * 
     * @param <E>
     *          the element type of the list
     * @param list
     *          the list
     * @param objects
     *          a list of objects to be removed from list
     */
    public static <E> void removeAll(List<E> list, List<? extends E> objects) {

        for (E object : objects) {
            remove(list, object);
        }

    }

    /**
     * Removes the given <code>object</code> from the given <code>list</code>,
     * comparing each element in the list with <code>equals</code>.
     * 
     * @param list
     *          a list
     * @param object
     *          an object to be removed from the list
     */
    public static <E> void remove(List<E> list, E object) {

        for (Iterator<E> it = list.iterator(); it.hasNext();) {
            if (it.next().equals(object)) {
                it.remove();
            }
        }
    }
}

Related

  1. remove(List list, T remove)
  2. remove(List list, T value)
  3. remove(Object o, List oldList)
  4. removeAfter(List children, int index)
  5. removeAll(List list, Object[] elements)
  6. removeAll(List idxs, List values)
  7. removeAll(List strings, String string)
  8. removeAll(List list, List indexes)
  9. removeAll(List toRemoveFrom, Collection elementsToRemove)