my dog learned polymorphism
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

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?


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

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
Bob Ruth
Ranch Hand

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

SCJP - 86% - June 11, 2009
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2851

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

|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

Joined: Oct 13, 2005
Posts: 46360
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

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="" target="_blank" rel="nofollow">Java</a>
I agree. Here's the link:
subject: String args[] vs. String[] args
It's not a secret anymore!