Integer.parseInt method for converting string to a number.
Java programming offers different methods for conversion between data types. For converting a numerical string to an integer java offers Integer.parseInt method. Have a look at the example below:
class ConvertString
{
public static void main(String args[])
{
String x=”12″;
int i=Integer.parseInt(x);
}
}
As shown in the example above x is a string in the form of number and to be used for calculations and other purpose needs to be converted to an integer data type. Integer.parseInt method converts string to number. By default, java accepts command line argument also in the form of string and so it becomes necessary to find a method that can convert a string to integer, Integer.parseInt is such method.










Leave Your Response