cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Converting string value to integer

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

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.

NarendraChandel
Contributor
0 Kudos

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