Difference between integer.parseint() and integer.valueof()

Integer.parseInt() returns primitive integer type (int).

public static Integer valueOf(String string) throws NumberFormatException {
    return valueOf(parseInt(string));
}

Integer.valueOf returns java.lang.Integer, which is the object representative of the integer.

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

So if you want an Integer object, instead of primitive type then you should go for Integer.valueOf() method.

Leave a comment