How to concert String to int? I've tried to use parseInt() and valueOf(), but it can not work.
thank you!
Best Regards,
Kevin Shen
Printable View
How to concert String to int? I've tried to use parseInt() and valueOf(), but it can not work.
thank you!
Best Regards,
Kevin Shen
Hi Kevin,
may be you used parseInt () in a wrong way.
Try this (I am sure this works, I use this code - if not, contact me again!!!):
Integer aInt = null;
int tmp = aInt.parseInt(aString);
Another possibility (I use this as well) is following:
String wrapperString = "2";
Integer wrapperInt;
int wrapperIntResult;
wrapperInt = Integer.valueOf(wrapperString);
wrapperIntResult = wrapperInt.intValue();
Andi
Try
String str = "12345";
Integer ii = new Integer(str);
int i = ii.intValue();
Timo
Integer.parseInt("1243");//returns an int
Float.parseFloat("12.23");//returns a float
Byte.parseByte("12");//returns a byte
Long.parseLong("12543241");//returns a long
Double.parseDouble("12355.3");//returns a double
All of the "wrapper" classes have the equivalent method except for Character.
Phill.