Java - 将整数转换为字符串 [英] Java - Convert integer to string
本文介绍了Java - 将整数转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个数字:
int number = 1234;
将其转换为字符串的最佳"方法是:
Which would be the "best" way to convert this to a string:
String stringNumber = "1234";
<小时>
我曾尝试搜索(谷歌搜索)寻找答案,但似乎没有多少人值得信赖".
推荐答案
有多种方式:
String.valueOf(number)
(我的偏好)"" + number
(不知道编译器是怎么处理的,也许和上面一样高效)Integer.toString(number)
String.valueOf(number)
(my preference)"" + number
(I don't know how the compiler handles it, perhaps it is as efficient as the above)Integer.toString(number)
这篇关于Java - 将整数转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文