wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes what is an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is an array" Watch "what is an array" New topic
Author

what is an array

Yudi Strange
Greenhorn

Joined: Jun 04, 2009
Posts: 7
Whats the difference between

String [] a;

and

String a;

Kindly explain.

[edited subject - was doubt]
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Yudi,

the one with the [] is called an array! Basically an array contains multiple Strings whereas the one without [] is exactly one object of type String.

You'll find more information on the website I posted ;-)

Marco
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Yudi please Use A Meaningful Subject Line for your posts to get better response...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Yudi Strange
Greenhorn

Joined: Jun 04, 2009
Posts: 7
@Ankit: I'll keep that in mind next time. Thanks for the heads up.

@Marco:
then what does String a[] means? Is it the same as String [] a?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Dear Yudi,

You Should read Way of Declare a Array

Hope this helps
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Both notations are identical and mean exactly the same. But in general

should be preferred instead of

because the the array brackets are part of the type declaration. So it's less confusing to put the brackets directly to the base type "String".

Marco




Yudi Strange
Greenhorn

Joined: Jun 04, 2009
Posts: 7
Thanks!!!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Yudi Strange wrote:@Ankit: I'll keep that in mind next time. Thanks for the heads up.

I edited the subject this time so other newcomers don't think that is the best way to ask a questin.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
Don't get me started about those stupid light bulbs.
 
subject: what is an array
 
Similar Threads
Tech Word Game
date format with MS Access database
ResultSet to Array
WA #1.....word association
How to convert byte array into string array?