Write a Java Program to convert string type variables into int.
Click Here to View the Solution!
public class IntToString
public static void main(String args)
String str1 = String.valueOf(num1);
Click Here to View the Output!
Click Here to View the Explanation!
- This program carries out the task of transforming a given string value into its Integer equivalent.
- For the conversion purpose
Integerclass, is employed.
- First a
Stringtype variables str1 is declared.
- Then the variable is passed to
valueOf()method as argument.
- The very next step involves the assignment of the resulting value to int type variable
- Finally, the result is displayed.
- This method
parseInt()in a sense that it first converts the values into an integer object then those objects are turned into integer values.
- This process is termed as ‘unboxing’, specifically in Java.