ateiob ateiob - 1 year ago 291
Java Question

Integer.valueOf() vs. Integer.parseInt()

Aside from

handling the minus sign (as documented), are there any other differences between

And since neither can parse
as a decimal thousands separator (produces
), is there an already available Java method to do that?

Answer Source

Actually, valueOf uses parseInt internally. The difference is parseInt returns an int primitive while valueOf returns an Integer object. Consider from the Integer.class source:

public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);

public static Integer valueOf(String s, int radix) throws NumberFormatException {
return Integer.valueOf(parseInt(s,radix));

public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));

As for parsing with a comma, I'm not familiar with one. I would sanitize them.

int million = Integer.parseInt("1,000,000".replace(",",""));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download