Java List Remove remove(List list, E object)

Here you can find the source of remove(List list, E object)

Description

Removes the given object from the given list, comparing each element in the list with equals.

License

Open Source License

Parameter

Parameter Description
list a list
object an object to be removed from the list

Declaration

public static <E> void remove(List<E> list, E object) 

Method Source Code


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

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

public class Main {
    /**//w w w. j  av  a 2s. c  o m
     * 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 models, int start, int count)
  2. remove(List list, List elements)
  3. remove(List list, Class type)
  4. remove(List as, int start, int end)
  5. remove(List list, E element)
  6. remove(List list, int index)
  7. remove(List list, int index)
  8. remove(List list, int index, T defaultValue)
  9. remove(List list, int position)