1
How to convert numeric String to int in Java?
1 Answer
0
For converting a numeric string to an int using the parseInt method of the Java Integer class. The parseInt method converts the String to an int, and throws a NumberFormatException if the string can’t be converted to an int type.
Example for converting numeric string to int in java -
| public class StringToIntExample { public static void main (String[] args) { String s = "100"; // Numeric String try { int i = Integer.parseInt(s.trim()); System.out.println("int i = " + i); } catch (NumberFormatException e) { System.out.println("NumberFormatException: " + e.getMessage()); } } } |