Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assign multiple values to string

 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to assign two values to an array. If the is condition is met then I I need to assign two values to S[i]. Can anyone please help me. Here is the code. Is it possible.

if(s[i] ==7)

{

s[i] = ALL+EZR

}


Thanks a lot
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "assign two values"? An element of an array has a single value, not two; you can assign the sum (or some other arithmetic combination) in the way your code does. What exactly are you trying to do?

Also, please check your private messages. You can do that by clicking on the "My Private Messages" link at the top of the page.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you compare a String and an int value ?



 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically I want to put two values ALL and EZR to a String array s[ic]. How would I do it?


if (s[ic] ==7)
{
assign ALL and EZR together to the s[ic]

}

I am sending an array to the method for extracting the data from the
database.Like below

rs = wda.getdata(s[ic], month year)

StringBuffer query = new StringBuffer("SELECT SUM(AAAAA), SUM(DDDDDDD) ");
query.append(" FROM "+Constants.emp+" WHERE CAT
='").append(s[ic]).append("' AND YEAR(DATE)=").append(year);

Thanks
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If "assign ALL and EZR together" means to concatenate their string values, then you can do that using the "+" operator:

will result in sc[i] being assigned "allezr" if sc is an array of String (which in your example it is obviously not, because you perform an equality comparison with the number 7). Is that what you want to do? If not, tell us what it means. (An array element can only hold a single value.)
[ March 30, 2008: Message edited by: Ulf Dittmer ]
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have two strings that represent numerics, Integer ( and other classes ) have a method, parseInt() and so on. You would have to parse the strings separartly, add them as a numeric and do toString() on the result. You can add two numbers, you cannot 'add' two strings. You have to do conversions in and out to make "3" plus "2" equal five. "3"+"2" gets you 32 as a string. The string representation of a number is a different type from the an actual number.

try this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic