This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String[] a vs String word[]

 
M Wilson
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Verify simple question.
What is the difference between declaring a variable String[] aString vs. String aString[]?
Thank you very much.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!".
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic