Java Array Remove removeElement(T[] array, T removeObject)

Here you can find the source of removeElement(T[] array, T removeObject)

Description

Removes a object to an existing array in Java.

License

Open Source License

Parameter

Parameter Description
array The array to remove from.
removeObject The object to remove.
T The generic array type.

Return

The array with the removed value.

Declaration

public static <T> T[] removeElement(T[] array, T removeObject) 

Method Source Code


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

import java.util.*;

public class Main {
    /**//from  ww  w . j a  v a2  s. c o  m
     * Removes a object to an existing array in Java.
     *
     * @param array The array to remove from.
     * @param removeObject The object to remove.
     * @param <T> The generic array type.
     *
     * @return The array with the removed value.
     */
    public static <T> T[] removeElement(T[] array, T removeObject) {
        List<T> result = new LinkedList<>();

        for (T item : array) {
            if (!removeObject.equals(item)) {
                result.add(item);
            }
        }

        return result.toArray(array);
    }
}

Related

  1. removeElement(Object[] array, Object entryToRemove)
  2. removeElement(String array[], String element, int occurrences)
  3. removeElement(String[] array, String remove)
  4. removeElement(String[] elements, String element)
  5. removeElement(T[] array, int i)
  6. removeElementInStringArray(String[] array, int index)
  7. removeEmpties(String[] array)
  8. removeEmtpyStrings(String[] strings)
  9. removeFirst(String[] args)