944,181 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2685
  • Java RSS
May 15th, 2007
0

arrays and strings

Expand Post »
what is the difference between arrays and strings at java?
Similar Threads
Reputation Points: 9
Solved Threads: 0
Light Poster
push is offline Offline
33 posts
since Apr 2007
May 15th, 2007
0

Re: arrays and strings

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.
Reputation Points: 938
Solved Threads: 357
Posting Maven
stultuske is offline Offline
2,528 posts
since Jan 2007
May 15th, 2007
0

Re: arrays and strings

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

What's the difference between a basketball and a barbequeue?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
May 16th, 2007
0

Re: arrays and strings

Click to Expand / Collapse  Quote originally posted by jwenting ...
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 -
Java Syntax (Toggle Plain Text)
  1. int X = 10;
Array -
Java Syntax (Toggle Plain Text)
  1. 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?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
isitintheback is offline Offline
8 posts
since May 2007
May 17th, 2007
0

Re: arrays and strings

thanks a lot for all.
Reputation Points: 9
Solved Threads: 0
Light Poster
push is offline Offline
33 posts
since Apr 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Card Games Help!!!!
Next Thread in Java Forum Timeline: java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC