Forums Register Login

typecast

+Pie Number of slices to send: Send
If i pass an integer value as String argument to some function, where i need to add it to integer value. How can i typecast argument from String to integer before adding. The problem i faced is

public int Sum(String str1,String str2){

int sum = str1+str2; //What i need to do here?
return sum;
}

public Static void main(String args[]){


obj.sum("123","456");


}
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Welcome to JavaRanch ( ) both of you.

Shaun: This question comes up frequently, at least once every three months, and you obviously know about the problem. It would help kiran nyala if you give a bit more explanation, and also explain why it isn't called "typecast"ing. Also, both of you, consider why that method could beneficially be declared static.
There is no "i" in denial. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 761 times.
Similar Threads
Strings Immutable ??
Passing a String by reference
null Strings concatenation
Referencing to another object
try again
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:30:59.