jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes (String[] args) vs. (String args[]) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "(String[] args) vs. (String args[])" Watch "(String[] args) vs. (String args[])" New topic

(String[] args) vs. (String args[])

Paul LaBrier

Joined: Apr 08, 2002
Posts: 21
Why would someone recommend using (String[] args) vs. (String args[]) in calling the main method? What is the difference?
Paul LaBrier
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
In main() there shouldn't be any difference. It only matters if you are making multiple declarations of arrays. For example:
String [] arr1, arr2;
I just declared two String array references. However, if I use
String arr1 [], arr2;
I declare one String array reference arr1, and one String reference arr2. To be able to declare 2 String array references, I can alternatively use
String arr1 [], arr2 [];
[ August 01, 2002: Message edited by: Anthony Villanueva ]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
What is the difference?
There isn't one as far as the compiler is concerned.
Java allows some flexibility in the style used to declare arrays (anywhere).
String[] args
String args[]
String []args
String args []
These are all equivalent and allowed in Java.
I prefer the String[] args style for all of my array declarations. I feel that it's more consistent with the normal identifier declaration style:
[ type ] [ identifier ] - Some type referred to by some identifier.
String[] args - A String array referred to by the identifier args.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link: http://aspose.com/file-tools
subject: (String[] args) vs. (String args[])
It's not a secret anymore!