0
Array
How can declaration , instantiation and initialzation of java array in one line
3 Antworten
+ 2
int[] a = new int[] {};
Declaration: int[] a
Instantiation: new int[] {}
Initialization: a = new int[] {}; // yeah, this overlaps mostly with instantiation since we're creating an instance to initialize variable a.
More detail is at: https://www.educative.io/edpresso/how-to-initialize-an-array-in-java
0
Building on Josh Greig's answer, you can initialize with values between the curly braces:
String chars[] = new String[] { "a", "b", "c" };
int nums[] = { 1, 2, 3 };
0
Tanks for your help