Normally I used one of these methods while converting an integer to a string:
Integer.toString(i)
orString.valueOf(i)
whilei
is an integer-value.
Are both ways are correct?
Normally I used one of these methods while converting an integer to a string:
Integer.toString(i)
or String.valueOf(i)
while i
is an integer-value.Are both ways are correct?
Both ways are the same :
/**
* Returns the string representation of the {@code int} argument.
* <p>
* The representation is exactly the one returned by the
* {@code Integer.toString} method of one argument.
*
* @param i an {@code int}.
* @return a string representation of the {@code int} argument.
* @see java.lang.Integer#toString(int, int)
*/
public static String valueOf(int i) {
return Integer.toString(i);
}