Java List Remove removeObject(List l, T o)

Here you can find the source of removeObject(List l, T o)

Description

Removes the first occurrence in the list of the specified object, using object identity (==) not equality as the criterion for object presence.

License

Open Source License

Parameter

Parameter Description
l The List from which to remove the object
o The object to be removed.

Return

Whether or not the List was changed.

Declaration

public static <T> boolean removeObject(List<T> l, T o) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /**/*  w  ww  .j  a  v  a2 s.  c o  m*/
     * Removes the first occurrence in the list of the specified object, using
     * object identity (==) not equality as the criterion for object presence. If
     * this list does not contain the element, it is unchanged.
     *
     * @param l The {@link List} from which to remove the object
     * @param o The object to be removed.
     * @return Whether or not the List was changed.
     */
    public static <T> boolean removeObject(List<T> l, T o) {
        int i = 0;
        for (Object o1 : l) {
            if (o == o1) {
                l.remove(i);
                return true;
            } else
                i++;
        }
        return false;
    }
}

Related

  1. removeIgnoreCase(List l, String s)
  2. removeIgnoreCase(String needle, List haystack)
  3. removeItems(List list, T... remove)
  4. removeList(List l)
  5. removeMember(String[] list, String id)
  6. removeObjectList(List list, V o)
  7. removeReference(List l, Object o)