java中的数组是定长的,无法动态增加长度。如果要扩充数组,只能通过重新定义数组,把旧数组内容拷贝到新数组中。
例如:
1、定义一个旧数组
int[] arrOld = new int[2]//旧数组定义2、要扩充数组长度到3,需要重新定义数组
int[] arrNew = new int[3]//定义新数组for(int i=0i<arrOld.lengthi++){
arrNew[i] = arrOld[i]//把旧数组中的元素拷贝到新数组中
}
java中的数组是定长的,无法动态增加长度。如果要扩充数组,只能通过重新定义数组,把旧数组内容拷贝到新数组中。
例如:
1、定义一个旧数组
int[] arrOld = new int[2]//旧数组定义2、要扩充数组长度到3,需要重新定义数组
int[] arrNew = new int[3]//定义新数组for(int i=0i<arrOld.lengthi++){
arrNew[i] = arrOld[i]//把旧数组中的元素拷贝到新数组中
}