I have used these two in Java and BlueJ but I am not sure where the difference between these two lies. Also in my book in the description given for parseInt there is a mention of radix 10. What exactly is radix 10?
Asked
Active
Viewed 496 times
0
-
radix = base, base 10 is our normal notation: 234 = 2*10² + 3*10 * 4. – Joop Eggen Dec 16 '19 at 15:01
1 Answers
5
The two methods are almost the same in terms of logic.
The difference is that valueOf
returns an Integer
and parseInt
returns an int
.
You can see that both call parseInt(s, 10)
, which means they treat the input String
as a number of radix (base) 10 (i.e. a decimal number).
public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));
}
public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);
}

Eran
- 387,369
- 54
- 702
- 768