Search code examples
javaparseint

Not able to convert String into Integer using parseInt() in java


I have a string, that I want to first split and then convert into integer. Here is my code :

String Table_data = "$452";          
String[] words=Table_data.split("\\$");
for(String w:words)
{
    int result = Integer.parseInt(w);
    System.out.print(result);
}

I have not much experience in java. I tried but its shows some error like "java.lang.NumberFormatException".

Please help. Thank you.


Solution

  • What you probably want is:

    String Table_data = "$452";  
    int result = Integer.parseInt(Table_data.replace("$", ""));