[DUPLICATE] What is the difference between(String [ ] arg) and (String arg[ ]) in java main method? | Sololearn: Learn to code for FREE!
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?

21st Sep 2017, 7:45 AM
Saurabh Shah
Saurabh Shah - avatar
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.
21st Sep 2017, 10:06 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
21st Sep 2017, 7:52 AM
Changed
Changed - avatar
+ 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... ^-^
21st Sep 2017, 11:14 AM
Femyk
Femyk - avatar
+ 9
hatsy is experienced 😃
21st Sep 2017, 10:09 AM
Changed
Changed - avatar
+ 9
@Guarav, yes she is 😊
21st Sep 2017, 10:30 AM
David Akhihiero
David Akhihiero - avatar
+ 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.
21st Sep 2017, 7:58 AM
Nick Nderitu
Nick Nderitu - avatar
+ 5
Both are same I hope.
21st Sep 2017, 2:30 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 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
23rd Sep 2017, 4:20 PM
Saurabh Shah
Saurabh Shah - avatar