how to convert string to int in java
String myString = "1234";
int foo = Integer.parseInt(myString);
3.9
10
int i = Integer.parseInt(myString);
Thank you!
10
0
3.5
8
int result = Integer.parseInt("500");
System.out.println(result) // prints 500 as int
Thank you!
8
0
5
1
There are two methods available in java to convert string to integer.
One is
Integer.parseInt() method and another one is
Integer.valueOf() method. Both these methods are static methods
of java.lang.Integer class. Both these methods throw
NumberFormatException if input string is not a valid integer.
Thank you!
1
0
3
2
String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);
Copy
Thank you!
2
0
4.27
9
String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);
Thank you!
9
0
Are there any code examples left?
New code examples in category Java