aspose file tools
The moose likes Beginning Java and the fly likes String[] a vs String word[] Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String[] a vs String word[]" Watch "String[] a vs String word[]" New topic
Author

String[] a vs String word[]

M Wilson
Greenhorn

Joined: May 23, 2010
Posts: 26
Verify simple question.
What is the difference between declaring a variable String[] aString vs. String aString[]?
Thank you very much.
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
No difference.

You just prefer to write String[] astring version, because in this way is more readable, it's more easy to see the type of the reference astring

Bye,
Nicola
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9947
    
    6

exactly.

When i see "String [] allNames" I mentally parse each part in order, as "a string array called allNames".

When I see " String allNames[]", I mentally parse it as "a string called allNames - OH WAIT!!! It's an ARRAY!!!".


Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32667
    
    4
The reason you mentally parse it like that, Fred, is that the first version correctly gives the type of the variable as an array of Strings, which is why it is preferred.

I think Sun ought to have prohibited foo array[] or similar, but wimped out of scaring off old C/C++ developers.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String[] a vs String word[]
 
Similar Threads
integer to string
Cloneable vs. copy constructor
String explanation
need help with Assignment 1.1
int vs Strings