Hello, I have a newbie question here. How do I convert the char and String data type to an integer in Java so that I can perform arithmetic operation?
Thanks.
::jumpto::
Printable View
Hello, I have a newbie question here. How do I convert the char and String data type to an integer in Java so that I can perform arithmetic operation?
Thanks.
::jumpto::
like this?
char crap = 'a';
int othercrap = (int)crap;
othercrap would have the ascii code value of 'a' then.
If you want to decode them in decimal, use the Integer.parseInt() method (IIRC)
something like
SlartyCode:String mystr = "42";
int theAnswer = Integer.parseInt(mystr);
I strongly recommend keeping a link on hand to the api documentation on http://java.sun.com . A quick run through there before coming here would probably save you time.
Integer.parseInt will do the job nice :D
Thanks, Integer.parseInt works.
Will Integer.parseInt convert the String datatype to int? :P
j/k, I just thought it was funny that it was mentioned 3 times. the java API owns j00.