How to convert a Java String to an Int?

Posted by Editorial Staff | Updated on

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

Program: String to int example

Following example demonstrates the Java String to int conversion process, handling for a possible NumberFormatException:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers