[英]What happens to integer when converted to String
I have many times converted a Integer
to String
but one thing I didn't understood what happens when an integer is converted to string. 我有很多次将Integer
转换为String
但是我不明白将整数转换为String会发生什么。
For Eg: 例如:
if I write int 1
then it is understood that one is numeric value and it can be used for calculations. 如果我写int 1
那么可以理解一个是数值,它可以用于计算。
When I write String.valueOf(1)
how 1
is represented now? 当我编写String.valueOf(1)
现在如何表示1
?
Can any one explain me what will be the Integer state when converted to string? 谁能解释一下转换为字符串时的整数状态?
Thanks for your time 谢谢你的时间
Internally, you can think of it being stored as an array of characters, each character representing a digit. 在内部,您可以将其存储为字符数组,每个字符代表一个数字。
In this case, you would just have an array of one character, with the ASCII value of '1'
, which is 0x31
. 在这种情况下,您将只有一个字符组成的数组,其ASCII值为'1'
,即0x31
。
If you want to know the details of exactly what is inside a Java String
, you will need to examine the Java source code for String
. 如果您想确切了解Java String
内部的详细信息,则需要检查Java源代码中的String
。
string is nothing more than array of char
, when you convert a single digit to string it is represented as char
variable. string只是char
数组,当您将一位数字转换为string时,它表示为char
变量。 it's no different then d
or |
和d
或|
没什么不同|
or %
. 或%
。 they are just characters which can't be used in any calculations or operations. 它们只是不能在任何计算或运算中使用的字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.