package TestOne;
import java.util.Arrays;
public class TestOperateArray {
public static void main(String[] args) {
int[] array = new int[]{4, 5, 6};
//Quickly look at the elements in the array.
System.out.println(Arrays.toString(array));
int extra = 90;
int[] array2 = new int[array.length + 1];
for (int i = 0; i < array.length; i++) {
array2[i] = array[i];
}
//Assigns the last element of the array2 to 4;
array2[array2.length-1]=extra;
array = array2;
System.out.println(Arrays.toString(array));
}
}
数组元素的添加
最新推荐文章于 2020-12-22 17:40:49 发布