aspose file tools*
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
Author

String args[] vs. String[] args

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Sometimes I see:



But sometimes I see:



How come? What is the difference... or maybe I should ask, why two ways?

Thanks.


We must know, we will know. -- David Hilbert
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I just posted some of my notes on this in this thread. Also see JLS - 10.2 Array Variables for more detail.

Note: Many people prefer the brackets next to the type rather than the identifier (that is, String[] s instead of String s[]) because it's more clear that the type is a String array.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
stricly personal preference


------------------------
Bob
SCJP - 86% - June 11, 2009
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi
to add in, String[] args type of declaratio causes all the variable on the right side to be arrays but String args[] does not.



Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
As people have already said, it makes no difference to the behaviour, except in the case of declaring multiple variables in one line. And, frankly, if you declare some Strings and some arrays of Strings, all in one line, you deserve to be forced to write Visual Basic for the rest of your career.

I think the "String args[]" version is one of the features of the Java language that was put in to help to make C programmers feel a bit more at home. It deserves to be ignored by all right-thinking Java programmers.

Just my humble opinion of course ;-)
[ July 03, 2007: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
I could hardly agree with you more, Peter Chase. It gets confusing when people writeOnly digits is an array. Even worse isThere everything is a [] array except digits which is a [][] array, but it is very easy to overlook that feature in a quick glance at the code.
Dawei Li
Greenhorn

Joined: Jul 01, 2007
Posts: 22
String args[] is old definition
String[] args is new definition.
The both have same function.
But the java recommends the new.


<a href="http://www.java-forums.org" target="_blank" rel="nofollow">Java</a>
 
Consider Paul's rocket mass heater.
 
subject: String args[] vs. String[] args