public class array {
public static void main(String[] args) {
myArray array=new myArray();
array.print();
myArray.intArray=(int[]) addArray(myArray.intArray,10);
array.print();
}
public static Object addArray(Object array,int len){
Object newArray=null;
Class obj=array.getClass().getComponentType();
newArray= Array.newInstance(obj,len);
System.arraycopy(array,0,newArray,0,Array.getLength(array));
return newArray;
}
}
class myArray {
static int[] intArray = {1, 2, 3, 5, 4};
public void print() {
for (int i = 0; i < intArray.length; i++) {
System.out.print(intArray[i] + " ");
}
System.out.println();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)