简体   繁体   English

整数转换为字符串时会发生什么

[英]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.

相关问题 在Java中将字节转换为String时,会发生什么情况? - What happens under the hood when bytes converted to String in Java? 在HIVE中将字符串隐式转换为int时会发生什么? - what happens when string is implicitly converted to int in HIVE? 当我尝试获取字符串的字节但从字符到字节的转换溢出整数长度时会发生什么? - What happens when I try to get the bytes for a String but the conversion from Character to Byte overflows the Integer length? 列表时会发生什么 <Integer> A =清单 <Integer> B? - What happens when List<Integer> A = List<Integer> B? 添加为json参数时,整数数组将转换为字符串 - Integer array get converted as a string when added as json parameter 当我们在java中创建Integer类的实例时会发生什么 - What happens when we create instance of Integer class in java 在Java中将负整数类型转换为long类型时会发生什么? - what happens when a negative integer is type cast to long in java? 将 null 分配给字符串 object 时会发生什么? - What happens when assigned null to String object? 当你增加一个整数超过它的最大值时会发生什么? - What happens when you increment an integer beyond its max value? 当 Java 字符串溢出时会发生什么? - What happens when a Java String overflows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM