0
How we convert string into int?
I found some relevant question/answers but could not understand.kindly someone explain it to me.
3 Réponses
0
int i=Integer.parseInt("12");
i=12;
0
In Java, you can use Integer.parseInt() to convert a String to int.
String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);
Alternatively, you can use Integer.valueOf(), it will returns an Integer object.
String number = "10";
Integer result = Integer.valueOf(number);
System.out.println(result);
If the string does not contain a parsable integer, a NumberFormatException will be thrown.
0
Using ParseInt method.. which is a static method.