English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To convert a string to a number in Java, use the Integer.parseInt() method. First, let's create a string and set its value.
String str = "45";
Now, get an Integer and use the Integer.parseInt() method.
Integer i = Integer.parseInt(str);
Let's see the complete example.
public class Demo { public static void main(String args[]) { String str = "45"; Integer i = Integer.parseInt(str); System.out.println("Num: " + i); } }
Output Result
Num: 45