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.

Leave a Comment