Blog Archive

Java convert String to Int example

Use Integer.parseInt method. It is extremely easy and most flexible way of converting String to Integer. Here is an example of string to int conversion...
package com.as400samplecode;

public class ConvertStringtoInteger {

    public static void main(String[] args) {

        String myString = "400";

            int myInteger = Integer.parseInt(myString);
        catch (NumberFormatException e){ 



Another way to convert String to Int is using the static method ValueOf(string)

Returns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string.

In other words, this method returns an Integer object equal to the value of:
new Integer(Integer.parseInt(s))


  1. Thank you. Found it interesting and useful. Java is a general purpose, high-level, class-based and object-oriented programming language. And we are Java training institutes in Chennai who also provide placement services to our students.

  2. This post contain the way which developer use to Java convert String. It's little bit difficult process but author of this post make it easy to write the example here. I have idea about Java coding and i understood it easily. However, I try to get assignment help in australia but when i came here then found a lot of articles on multiple topics of coding. Thanks for the owner of this site.