0

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?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724

1 Answers1

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