I've seen this written two different ways:
public static void main(String[] args)
and
public static void main(String args[])
Is there a difference here? Which one is preferred? Any help would be greatly appreciated.
I've seen this written two different ways:
public static void main(String[] args)
and
public static void main(String args[])
Is there a difference here? Which one is preferred? Any help would be greatly appreciated.
There is no difference. I prefer String[] because I think the fact that this is an array is part of the type.
No way is "better" than the other, as both are valid java syntaxes. You simply should be consistent, and use the one that makes most sense to you in the end. You're doing nothing more than declaring a String
array called args
as a parameter. Either is valid for this. I personally prefer String[] args
but both are technically valid.
They are equivalent. Look at this example from Java Language Specification:
The [ ] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.
byte[] rowvector, colvector, matrix[];
This declaration is equivalent to:
byte rowvector[], colvector[], matrix[][];