This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes typecast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "typecast" Watch "typecast" New topic
Author

typecast

kiran nyala
Ranch Hand

Joined: Sep 21, 2009
Posts: 47

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");


}
shaun jacob
Greenhorn

Joined: Jan 11, 2010
Posts: 7
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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.
 
 
subject: typecast