数组
1、定义方式:
int[] arr = new int[3];//创建一个长度为3的数组,数组中每个数默认值为0 int[] arr = new int[] {1,2,3}; int[] arr = {1,2,3};
2、数组的复制
方法一:
int[] arr1 = new int[] {1,2,3}; int[] arr2 = new int[arr1.length]; for(int i=0;i<arr1.length;i++) { arr2[i]=arr1[i]; }
方法二:
int[] arr1 = new int[] {1,2,3}; int[] arr3 = Arrays.copyOf(arr1, arr1.length);