arrays and strings

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2007
Posts: 33
Reputation: push is an unknown quantity at this point 
Solved Threads: 0
push push is offline Offline
Light Poster

arrays and strings

 
0
  #1
May 15th, 2007
what is the difference between arrays and strings at java?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: arrays and strings

 
0
  #2
May 15th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: arrays and strings

 
0
  #3
May 15th, 2007
Strings aren't arrays, arrays aren't strings.

What's the difference between a basketball and a barbequeue?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 8
Reputation: isitintheback is an unknown quantity at this point 
Solved Threads: 1
isitintheback isitintheback is offline Offline
Newbie Poster

Re: arrays and strings

 
0
  #4
May 16th, 2007
Originally Posted by jwenting View Post
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 -
  1. int X = 10;
Array -
  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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 33
Reputation: push is an unknown quantity at this point 
Solved Threads: 0
push push is offline Offline
Light Poster

Re: arrays and strings

 
0
  #5
May 17th, 2007
thanks a lot for all.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC