Here you can find the source of removeElement(T[] array, T removeObject)
Parameter | Description |
---|---|
array | The array to remove from. |
removeObject | The object to remove. |
T | The generic array type. |
public static <T> T[] removeElement(T[] array, T removeObject)
//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); } }