How to convert / cast long to String? How to convert / cast long to String? java java

How to convert / cast long to String?


See the reference documentation for the String class: String s = String.valueOf(date);

If your Long might be null and you don't want to get a 4-letter "null" string, you might use Objects.toString, like: String s = Objects.toString(date, null);


EDIT:

You reverse it using Long l = Long.valueOf(s); but in this direction you need to catch NumberFormatException


String strLong = Long.toString(longNumber);

Simple and works fine :-)


Long.toString()

The following should work:

long myLong = 1234567890123L;String myString = Long.toString(myLong);