+ 4
[DUPLICATE] String args [ ] or String [ ] args
In Java, When declaring main method, Sometimes we code : public static void main (String[ ] args) and other times : public static void main (String args[ ] ) Is there any difference between them? because result will be the same in Hello World Program. (I am novice in Java). And what if we code : public static void main (String[ ] args [ ] ) Any Explanation?
6 Answers
+ 4
There's no difference. You can use any and the result won't change. That is because that is an argument in the main method, an array of strings, soon in the course you will learn that, you can declare arrays in two ways
string arr[1]
string[1] arr
+ 5
These are the declaration syntax if array..
Arrays can be declared in many ways...
they are:
String [ ]args ;recommended way.
String args[ ] ;
String ... args;(opertor... called ellipse opertor).
but String[] args[] is the 2D array. (not valid argument in for main() method)
but first 3 are valid arguments for main method.
+ 3
args doesn't have to be empty
there can be passed something from command line when you start your program
+ 2
Thank you @noname.
+ 1
@noname so does my program declare an empty array of strings?
+ 1
Not exactly your program, we all are taught to declare it on the main method, and I suppose it's got its purpose, but I don't know what is it, sorry