Android Array Remove removeElement(Class kind, T[] array, T element)

Here you can find the source of removeElement(Class kind, T[] array, T element)

Description

remove Element

Declaration

@SuppressWarnings("unchecked")
    public static <T> T[] removeElement(Class<T> kind, T[] array, T element) 

Method Source Code

//package com.java2s;
import java.lang.reflect.Array;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T[] removeElement(Class<T> kind, T[] array, T element) {
        if (array != null) {
            final int length = array.length;
            for (int i = 0; i < length; i++) {
                if (array[i] == element) {
                    if (length == 1) {
                        return null;
                    }//from  www.j a  va  2  s  . c  o  m
                    T[] result = (T[]) Array.newInstance(kind, length - 1);
                    System.arraycopy(array, 0, result, 0, i);
                    System.arraycopy(array, i + 1, result, i, length - i
                            - 1);
                    return result;
                }
            }
        }
        return array;
    }
}

Related

  1. remove(double[] array, int index)
  2. remove(float[] array, int index)
  3. remove(int[] array, int index)
  4. remove(long[] array, int index)
  5. remove(short[] array, int index)
  6. removeElement(T[] array, Object element)
  7. removeElement(boolean[] array, boolean element)
  8. removeElement(byte[] array, byte element)
  9. removeElement(char[] array, char element)