11 Years
Discussion Span
Last Post by push

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.


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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.