How to convert / cast long to String?

前端 未结 8 1077
借酒劲吻你
借酒劲吻你 2020-12-04 05:14

I just created sample BB app, which can allow to choose the date.

DateField curDateFld = new DateField(\"Choose Date: \",
  System.currentTimeMillis(), DateF         


        
相关标签:
8条回答
  • 2020-12-04 05:44

    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

    0 讨论(0)
  • 2020-12-04 05:46
    String longString = new String(""+long);
    

    or

    String longString = new Long(datelong).toString();
    
    0 讨论(0)
  • 2020-12-04 05:48

    Just do this:

    String strLong = Long.toString(longNumber);
    
    0 讨论(0)
  • 2020-12-04 05:53
    String logStringVal= date+"";
    

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

    0 讨论(0)
  • 2020-12-04 05:56

    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);
    
    0 讨论(0)
  • 2020-12-04 06:05

    Long.toString()

    The following should work :

    long myLong = 1234567890123L;
    String myString = Long.toString(myLong);
    
    0 讨论(0)
提交回复
热议问题