Copy the code code as follows:
//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()) {//Judge the type
return null;
}
// get the array's componentType
Class componentType = objArr.getClass().getComponentType();//Get the type
//get a newInstance of a Array object Object newArray = Array.newInstance(componentType, newLength);//Create a new array object
//copy the array
System.arraycopy(objArr, 0, newArray, 0, Array.getLength(objArr));//Copy the original array data to the new array, where newLength must be greater than the length of the element objArr, otherwise this sentence will report an error
return newArray;
}