//Java code to convert String to Integer
public class Main {
public static void main(String args[]) {
String str = "12345";
//variable to store result
int result = 0;
//converting string to integer
//method 1
result = Integer.valueOf(str).intValue();
System.out.println("result (value of str as integer) = " + result);
//method 2
result = Integer.parseInt(str);
System.out.println("result (value of str as integer) = " + result);
}
}
Output
result (value of str as integer) = 12345
result (value of str as integer) = 12345
Java code to convert a String to Integer
Output