gpt4 book ai didi

java - 整数到字符串的转换

转载 作者:行者123 更新时间:2023-12-01 07:52:47 27 4
gpt4 key购买 nike

通常我在将整数转换为字符串时使用以下方法之一:

  • Integer.toString(i)
  • String.valueOf(i)i是一个整数值。

这两种方式都正确吗?

最佳答案

两种方式都是一样的:

/**
* 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);
}

关于java - 整数到字符串的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34512038/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com