Javatpoint Logo
Javatpoint Logo

Java Convert String to int

Java Convert String to int

We can convert String to int in java using Integer.parseInt() method. To convert String into Integer, we can use Integer.valueOf() method which returns instance of Integer class.

Scenario

It is generally used if we have to perform mathematical operations on the string that contains number. Whenever we get data from textfield or textarea, entered data is received as a string. If entered data is integer, we need to convert string to int. To do so, we use Integer.parseInt() method.

Signature

The parseInt() is the static method of Integer class. The signature of parseInt() method is given below:

Java String to int Example: Integer.parseInt()

Let's see the simple code to convert string to int in java.

Let's see the simple example of converting String to int in java.

Test it Now

Output:

200100
300

Java String to Integer Example: Integer.valueOf()

The Integer.valueOf() method converts String into Integer object. Let's see the simple code to convert String to Integer in java.

Test it Now

Output:

300
Next TopicJava int to String




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials