Image

Imageerikwilson wrote in Imagejava_dev

Integer.parseInt()

Hi everyone,

I'm having a problem getting parseInt to work right.
Here's my problem:

Let's say I have
String string1 = "+9999999999";

and I want to pull apart the sign and then the digits and store the digits in a new int.

Currently I'm trying:

StringTokenizer token = new StringTokenizer(string1, "+-");
String string2 = token.nextToken(); //THIS WILL RETURN A STRING WHICH IS "9999999999"
Next I try to parse it to an integer:

int int1 = Integer.parseInt(string2);

However, when I do this, it throws a numberFormatException because my String is not in the proper format. I've every way I can think of to take string1 apart and store the digits but everyway results in a numberFormatException.

Do anyone have any other ideas how I could do this or where I'm going wrong?