New course! Every coder should learn Generative AI!
Try a free lesson+ 7
[DUPLICATE] What is the difference between(String [ ] arg) and (String arg[ ]) in java main method?
Output remains same but what is the dif?
8 Answers
+ 20
IIRC, the former is the recommended way to declare an array. The latter is only there for C/C++ programmers to get used to Java.
Still, there is a small difference:
int[] foo, bar; // will declare both as arrays.
int foo[], bar; // will only declare foo as an array.
+ 15
no difference will be there in the output ... both are same thing & can be used interchangibly in java ,
thats a diferent way to write a same thing
+ 15
Yea. @Hatsy is right. The latter is just legacy to make C/C++ programmers to "feel at home".
The syntax is also not robust as the former...
^-^
+ 9
hatsy is experienced 😃
+ 9
@Guarav, yes she is 😊
+ 8
In java. You can declare an array as arr[] or []arr. I was surprised that in C# you can only declare an array as []arr.
+ 5
Both are same I hope.
+ 1
That is a convenience the compiler offers, they're equivalent.
They are semantically identical. The int array[]syntax was only added to help C programmers get used to java.
int[] array is much preferable, and less confusing.
there is a difference (I forgot because I never declare more than one variable at a time):
int[] foo, bar; // both are arrays
int foo[], bar; // foo is an array