1、数组初始化
1.1 一维数组
数组元素类型 数组名 = new 数组元素类型[数组元素的个数]
int month = new int[12];
1.2 二维数组
int myarr[][] = new int[2][4];
int myarr[2][2] = {{2,2},{1,2}};
2、数组基本操作
- 遍历数组
- 填充替换数组元素
- fill(int[] a,int value)
- a:为进行替换的数组
- value:要存储数组中所有元素的值
- fill(int[] a,int fromIndex,int toIndex,int value)
- a:为进行替换的数组
- value:要存储数组中所有元素的值
- fromIndex:开始索引(包含)
- toIndex:结束索引(不包含)
- fill(int[] a,int value)
- 对数组进行排序
Arrays.sort()
- 复制数组:使用Arrays类的copyOf
- copyOf(arr,int newlength)
- arr:要进行复制的数组
- newlength:复制后的新数组的长度。超出复制数组补零,小于则截取到所需长度位置。
2.copyOfRange(arr,int fromIndex,int toIndex)