PDA

Click to See Complete Forum and Search --> : A Java Question


Falcon21
August 17th, 2004, 12:45 PM
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::

el-half
August 17th, 2004, 01:01 PM
like this?

char crap = 'a';
int othercrap = (int)crap;

othercrap would have the ascii code value of 'a' then.

slarty
August 17th, 2004, 03:36 PM
If you want to decode them in decimal, use the Integer.parseInt() method (IIRC)

something like


String mystr = "42";
int theAnswer = Integer.parseInt(mystr);


Slarty

Juridian
August 18th, 2004, 11:05 PM
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.

Death_Knight
August 19th, 2004, 02:10 PM
Integer.parseInt will do the job nice :D

Falcon21
September 3rd, 2004, 03:46 PM
Thanks, Integer.parseInt works.

skiddieleet
September 5th, 2004, 04:54 AM
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.