Converting String to int in Java?
ReportQuestion
Please briefly explain why you feel this question should be reported .
Integer x = Integer.valueOf(str);
// or
int y = Integer.parseInt(str);
There is a slight difference between these methods:
-
valueOf
returns a new or cached instance ofjava.lang.Integer
parseInt
returns primitiveint
.
To convert a string into an int, use:
String str = "1234";
int num = Integer.parseInt(str);
To convert a number into a string, use:
int num = 1234;
String str = String.valueOf(num);
0
Java
10 months
2021-08-05T18:41:47+02:00
2021-08-05T18:41:47+02:00 0 Answers
9 views
0
Leave an answer