Java Array Remove removeElement(Object[] array, Object entryToRemove)

Here you can find the source of removeElement(Object[] array, Object entryToRemove)

Description

Removes element from an array.

License

GNU General Public License

Parameter

Parameter Description
array a parameter
value a parameter

Declaration

public static Object[] removeElement(Object[] array,
        Object entryToRemove) 

Method Source Code

//package com.java2s;
/*//from w w  w. j a v  a  2s  . c om
 Pulsar
 Copyright (C) 2013-2015 eBay Software Foundation
 Licensed under the GPL v2 license.  See LICENSE for full terms.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Removes element from an array. It's faster that turning array into stream and then using WHERE clause.
     * 
     * @param array
     * @param value
     * @return
     */
    public static Object[] removeElement(Object[] array,
            Object entryToRemove) {
        if (array != null && entryToRemove != null) {
            List<Object> list = new ArrayList<Object>();
            for (Object entry : array) {
                if (entry == null || !entry.equals(entryToRemove)) {
                    list.add(entry);
                }
            }
            return list.toArray();
        }
        return array;
    }
}

Related

  1. removeAt(T[] array, int index)
  2. removeByPrefix(String[] array, String prefix)
  3. removeByteOrderMark(final byte[] input)
  4. removeCommonWords(String[] words)
  5. removeElement(final E[] array, final int index)
  6. removeElement(String array[], String element, int occurrences)
  7. removeElement(String[] array, String remove)
  8. removeElement(String[] elements, String element)
  9. removeElement(T[] array, int i)