Java – integer (numeric) to string

This is my simple question

We can convert integer, float and double into string, such as string s = "I"; So why do we need string s = integer toString(i); ? Just the requirements of OO programmig?

thank you

Solution

Because "I" is a very bad practice It converts an empty string and an integer into a string by connecting them, which internally leads to the creation of an instance of StringBuilder, the addition of an empty string, and the addition of integer Call tostring(), append the transformation, and then call StringBuilder toString().

Integer. Tostring() can do the required operation: convert an integer to a string Therefore, it is more efficient, clear and readable because it tells it what it does: convert integers to strings

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>