Is there a difference between main(String args[]) and main(String[] args)?
Semantically, they are identical. However, I'd recommend using the latter syntax (String[] args
) when declaring arrays. The former syntax is there mainly for compatibility with C syntax.
Since String[]
, as a whole, is the type of the object in Java, it's more consistent and clear not to split it up.
A similar question addresses the []
after method argument list.
There's no difference, but putting the brackets after the type (String[]
) is the more common practice in Java.
Both of them are absolutely the same. Please refer to Java Language Specification (JLS) to see the syntax used in java.
String[] args or String args[] will create an array (reserves a place in memory)with no size and name args.
Let us Consider:
String [] x;
putting the [] after the name. Why? because it avoids subtle problems like this:-
String x [] , y; //x[] is an array but y is a String
String [] x y ; //two arrays x[] and y[] both