它需要一个Array并将指定的元素添加到它的末尾
//来自 n o w j a v a . c o m //package com.nowjava; import java.lang.reflect.Array; public class Main { /** * It takes an Array and add the specified element to the end of the it * * @param <T> Type * @param typeClass the class of the type of the array * @param array the array you want to operate on * @param element the element you want to add * @return the new extended array */ public static <T> T[] addElement(Class<T> typeClass, T[] array, T element) { @SuppressWarnings("unchecked") T[] newArray = (T[]) Array.newInstance(typeClass, array.length + 1); int i = 0; while (i < array.length) { newArray[i] = array[i];