Java中初始化數組有以下幾種方法:
int[] arr = {1, 2, 3, 4, 5};
int[] arr = new int[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
int[] arr = new int[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = i + 1;
}
int[] arr = new int[5];
Arrays.fill(arr, 1);