Java String to Int example

In this tutorial we see how to convert string to int.

Generally when we enter int values in text filed, text area and submit the form, the parameters we will receive like as a string format in server side. In that case we need to convert those values in int format and perform the operations.

we have two methods to use to convert  string to int in java.

First one :

Integer.parseInt()  method is use to convert  string to int in java.

Integer.valueOf() returns primitive int.

Let see the code example of Integer.parseInt().

OutPut:

 

Second approach:

Integer.valueOf()  method is use to convert  string to int in java.

Integer.valueOf() method returns Integer Object.

 

OutPut:

 

 

 

 

 

 

Posted in java conversion and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.