954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

arrays and strings

what is the difference between arrays and strings at java?

push
Light Poster
33 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

a String is one Object (of the type String). an array is a small collection of Objects.

for instance: you know you need to keep seven String-Objects, containing the days of the week, in your program.

String dayOne = "Monday";
String dayTwo = "Tuesday";
...
like here above, this are seperate Objects of the type String.

if you would use:

String week[] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

then, you have one array, containing seven String Objects.

now you can use:

dayOne = week[0];

=> this will load the first element of the array into the variable with the name dayOne.

stultuske
Posting Sensei
3,119 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 432
 

Strings aren't arrays, arrays aren't strings.

What's the difference between a basketball and a barbequeue?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Strings aren't arrays, arrays aren't strings.

What's the difference between a basketball and a barbequeue?

What he said. They have absolutely nothing in common.

Maybe you meant what is the difference between a Variable and an Array?

Because essentially an Array is a variable, which can contain a multiple number of expressions.

But, to answer what you're asking, a String is like a sentence, for example:
"This is a string."

An Array is exactly what I stated above, it's a variable that contain multiple numeric values, or technically I guess it could be used to store anything, and more than one!

For example:

Normal Variable -

int  X = 10;

Array -

int X[3]


Maybe you saw something like this:

String months[] = 
       {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 
        "July", "Aug", "Sep", "Oct", "Nov", "Dec"};

And it confused you possibly?

isitintheback
Newbie Poster
8 posts since May 2007
Reputation Points: 10
Solved Threads: 1
 

thanks a lot for all.

push
Light Poster
33 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You