on 04-08-2009 7:36 AM
Hi,
Is it possible to convert a string value to integer. Like if the string contains 9, i need to convert it to integer 9.
Thanks.
Hi
Yes you can convert String to interger but you have to write string as integer not exceed integer rage.
String str="9";
int out=Integer.parseInt(str);
System.out.println("test"+out);
thanks
jati
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
All these response will be resolve ur problem. If it is not resolving ur problem then let me know what exact error u r facing now.
You can use the Integer.parseInt option but if the value come as a string then it will throw numberformat exception error.
So use this in a catch block for throwing the exception
Thanks
Kanai
Thanks
Kanai
Hi,
You can very well convert an String to an integer if the value in the string is an integer.
try{
int value = Integer.parseInt(str); //str is a string variable
}catch(NumberFormatException ex)
{
// If str contains value other than numeric then number format exception will be thrown.
}
Thanks & Regards,
Jaya.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi u can user the below code
String abc = "9";
int value = Integer.parseInt(abc);
it will covert String to int value.
hope this will help
Regards
Narendra
Edited by: Narendra Singh on Apr 8, 2009 8:42 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.