Is there a difference between main(String args[]) and main(String[] args)?
Is there a difference between:
public void main(String args[]) { ... }
and
public void main(String[] args) { ... }
I don't believe so, but I am wondering.
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.