String to Int Conversion

This section illustrates you how to convert a string into its integer equivalent.

String to Int Conversion

String to Int Conversion

     

This section illustrates you how to convert a string into its integer equivalent. To demonstrate the conversion of string into an integer we are taking an example that take string as input and converts it into its integer equivalent value.

The given example takes a string as input and then calls the parseInt() method of the Integer wrapper class to convert the string into the its integer equivalent and receives that integer value into a Intval variable and then displays that converted value on the console.

public class ConvertStringToInt {
  public static void main(String[] args) {
  String StrtoInt = "894";
  int Intval = Integer.parseInt(StrtoInt);
  
  System.out.println(Intval);
  }
}

 

Here is the Output of the program:

C:\>java StringToIntConversion
894