Below is the source for both method as of JDK 8
This is the source for Intger.toString()
public static String toString(int i) {
if (i == Integer.MIN_VALUE)
return "-2147483648";
int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
char[] buf = new char[size];
getChars(i, size, buf);
return new String(buf, true);
}
And this is the source for String.valueOf(int)
public static String valueOf(int i) {
return Integer.toString(i);
}
As you can see there will be barely any difference in the performance , Integer.toString()
is called in both cases
But I you have to choose one then the answer is Integer.toString()
because that way i can reduce the overhead of calling String.valueOf(int)
it will be barely anything , but as you may know a method call involves many things like putting method call on stack , saving state and control return position , then poping it off the stack , that all will be avoided, but still computers are too fast so it doesn't count