Java ArrayList Remove removeByReference(ArrayList list, T object)

Here you can find the source of removeByReference(ArrayList list, T object)

Description

Removes the given object from the list using reference equality, not equals()

License

Open Source License

Parameter

Parameter Description
list a parameter
object a parameter

Declaration

public static <T> boolean removeByReference(ArrayList<T> list, T object) 

Method Source Code


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

import java.util.ArrayList;

public class Main {
    /**// ww  w. ja va 2  s . com
     * Removes the given object from the list using reference equality, not equals()
     * @param list
     * @param object
     * @return
     */
    public static <T> boolean removeByReference(ArrayList<T> list, T object) {
        if (list == null)
            return false;
        int size = list.size();
        for (int i = 0; i < size; i++) {
            if (list.get(i) == object) {
                list.remove(i);
                return true;
            }
        }
        return false;
    }
}

Related

  1. removeAdditionalRanges(String line, ArrayList indices, ArrayList newRanges)
  2. removeAllFromArrayList(ArrayList collection, Collection toRemove)
  3. removeAllListaProd(ArrayList lista)
  4. removeAlreadyParsedFolders(ArrayList listStrings, String pickup, String limit)
  5. removeDuplicates(ArrayList al)
  6. removeDuplicates(ArrayList a)
  7. removeDuplicateWithOrder(List arrayList)
  8. removeElementsFromIndexToEnd(ArrayList list, int index)