//param objArr the expanded object of Array.
//param newLength the length of the new Array
public static Object getNewArr(Object objArr, int newLength) {
if (!objArr.getClass().isArray()) {//判斷類型
return null;
}
// get the array's componentType
Class componentType = objArr.getClass().getComponentType();//獲得類型
//get a newInstance of a Array object Object newArray = Array.newInstance(componentType, newLength);//新建數(shù)組對象
//copy the array
System.arraycopy(objArr, 0, newArray, 0, Array.getLength(objArr));//把原數(shù)組數(shù)據(jù)copy到新建數(shù)組中,其中newLength要大于元objArr的length,否則此句報錯
return newArray;
}