Efficient way to convert long to String in Java

I used

long a = 123456789;
String b = a+"";

to convert a value long(or int) to Stringor in this perspective consider it as a String. My question is, is it good to do this? Are there any negative consequences?

And is there any difference in using String.valueOf()vs Long.toString()?

thank

+4
source share
2 answers

This is normal, as the recent JVM is likely to reduce it to:

String b = String.valueOf(a);

, Java, . a null, b = "null" ? NPE? , .

+4

-, - L :

Long a = 123456789L;

String.valueOf() Long.toString() long , a (long), Object#toString():

String b = a.toString();

a, , (long), String.valueOf() Long.toString() , , .

+4

Source: https://habr.com/ru/post/1599020/


All Articles