通常我在将整数转换为字符串时使用其中一种方法:
Integer.toString(i)
要么
String.valueOf(i)
while i
是整数值.
两种方式都是正确的吗?
两种方式都是一样的:
/** * Returns the string representation of the {@code int} argument. ** 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); }