Is there a difference between main(String args[]) and main(String[] args)?

Jérôme Verstrynge picture Jérôme Verstrynge · May 13, 2011 · Viewed 34.7k times · Source

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.

Answer

Mehrdad Afshari picture Mehrdad Afshari · May 13, 2011

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.