Java数组声明和初始化
//数组的声明和初始化
double[] prices;
//静态初始化,数组变量的赋值和数组元素的赋值操作同时进行
prices = new double[]{1, 2.1, 3.22};
//动态初始化,数组变量的赋值和数组元素的赋值操作分开进行
String[] foods = new String[4];
//其它正确的方式
int arr[] = new int[4];
int[] arr1 = new int[]{1, 2, 3, 4};
int[] arr2 = {1, 2, 3, 4};//类型推断
int arr5[][] = new int[][]{{1} , {2}};
int[] arr6[] = new int[][]{{1} , {2}};
int arr7[][] = {{1} , {2}};//类型推断
int[] arr8[] = new int[3][];
//错误的方式
//int[] arr3 = new int[4]{1, 2, 3, 4};
//int[4] arr4 = new int[4];
标签:初始化,Java,int,数组,new,赋值
From: https://www.cnblogs.com/zuoyeb/p/18041613