Java静态数组的初始化方式有以下几种:
int[] arr = {1, 2, 3, 4, 5};
int[] arr = new int[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = i + 1;
}
int[] arr;
static {
arr = new int[]{1, 2, 3, 4, 5};
}
int[] arr = initializeArray();
public static int[] initializeArray() {
return new int[]{1, 2, 3, 4, 5};
}