此方法允许合并2个数组
//package com.nowjava; import java.lang.reflect.Array; /* 来自 *n o w j a v a . c o m - 时 代 Java*/ public class Main { /** * This method allows to merge 2 arrays * * @param <T> the generic type * @param firstArray the first array to merge * @param secondArray the second array to merge * @return merged array */ public static <T> T[] mergeArrays(T[] firstArray, T[] secondArray) { int firstArrayLength = firstArray.length; int secondArrayLength = secondArray.length; @SuppressWarnings("unchecked") T[] mergedArray = (T[]) Array.newInstance(firstArray.getClass() .getComponentType(), firstArrayLength + secondArrayLength); System.arraycopy(firstArray, 0, mergedArray, 0, firstArrayLength);