There are three main ways to convert a long value to String in Java e.g. by using Long.toString(long value) method, by using String.valueOf(long) and by concatenating with an empty String. You can use any of these method to convert a long data type into String object. It's not very different than from how you convert an int to String in Java. Same method applies here as well. String concatenation seems the easiest way of converting a long variable to String, but others are also convenient. If you look Java code for valueOf() method from java.lang.String class you will realize that it actually calls the toString() method of java.lang.Long class for conversion, which means there is only one method where logic of converting primitive long to String is written. Nevertheless, if you are not converting long in loop all method will perform same, but if you have to convert large number of long values to String then directly using Long.toString() method can be quite useful.
Read more »
No comments:
Post a Comment