• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would someone recommend using (String[] args) vs. (String args[]) in calling the main method? What is the difference?
Thanks,
Paul LaBrier
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic