wood burning stoves*
The moose likes Java in General and the fly likes assign multiple values to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "assign multiple values to string" Watch "assign multiple values to string" New topic
Author

assign multiple values to string

phani kon
Ranch Hand

Joined: Apr 06, 2005
Posts: 251
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
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
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.


Ping & DNS - my free Android networking tools app
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
How would you compare a String and an int value ?



phani kon
Ranch Hand

Joined: Apr 06, 2005
Posts: 251
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
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
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

Joined: Sep 17, 2006
Posts: 1282
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assign multiple values to string