How to convert / cast long to String?

依然范特西╮ 提交于 2019-11-27 16:45:19
Gregory Pakosz

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);
MR.M

very simple, just concatenate the long to a string.

long date = curDateFld.getDate(); 
String str = ""+date;
iKushal

1.

long date = curDateFld.getDate();
//convert long to string
String str = String.valueOf(date);

//convert string to long
date = Long.valueOf(str);

2.

 //convert long to string just concat long with empty string
 String str = ""+date;
//convert string to long

date = Long.valueOf(str);
tkfwr
String logStringVal= date+"";

Can convert the long into string object, cool shortcut for converting into string...but use of String.valueOf(date); is advisable

String longString = new String(""+long);

or

String longString = new Long(datelong).toString();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!