Conversion from String to int


 

Conversion from String to int

In this tutorial we will learn how to convert a string type data to int type data.

In this tutorial we will learn how to convert a string type data to int type data.

Conversion from String to int:

In this tutorial we will learn how to convert a string type data to int type data.

Description:

This program will take a String value from mystring variable. The line int myint = Integer.parseInt(mystring); converts the mystring string type value to myint int type value. The parseInt() method coverts any type data to int type data.

Code:

class Stringtoint {
	public static void main(String[] args) {
		try {
			String mystring = "100";
			int myint = Integer.parseInt(mystring);
			System.out.println("Converted value from string to int is: "
					+ myint);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
}
 

Output:

Download this code

Ads