Android Array Add appendElement(Class kind, T[] array, T element)

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

Description

append Element

Declaration

@SuppressWarnings("unchecked")
    public static <T> T[] appendElement(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[] appendElement(Class<T> kind, T[] array, T element) {
        final T[] result;
        final int end;
        if (array != null) {
            end = array.length;// w w  w . j ava 2 s  .  c  o m
            result = (T[]) Array.newInstance(kind, end + 1);
            System.arraycopy(array, 0, result, 0, end);
        } else {
            end = 0;
            result = (T[]) Array.newInstance(kind, 1);
        }
        result[end] = element;
        return result;
    }
}

Related

  1. addAll(float[] array1, float... array2)
  2. addAll(int[] array1, int... array2)
  3. addAll(long[] array1, long... array2)
  4. addAll(short[] array1, short... array2)
  5. append(String[] original, String element)
  6. appendInt(int[] cur, int val)
  7. arrayappend(T[] array, T[] append)
  8. arrayappend(T[] array, T[] append, int size)
  9. arraybyteappend(byte[] array, byte[] append)