Get empty string when null

后端 未结 7 756
予麋鹿
予麋鹿 2020-12-07 19:55

I want to get string values of my fields (they can be type of long string or any object),

if a field is null then it should return empty string, I did this with guav

7条回答
  •  鱼传尺愫
    2020-12-07 20:29

    If alternative way, Guava provides Strings.nullToEmpty(String).

    Source code

    String str = null;
    str = Strings.nullToEmpty(str);
    System.out.println("String length : " + str.length());
    

    Result

    0
    

提交回复
热议问题