StringBuilder append() and null values

后端 未结 8 926
借酒劲吻你
借酒劲吻你 2021-02-06 21:54

I have a list of Strings, and I want to concatenate them with spaces in between. So I\'m using StringBuilder. Now if any of the Strings ar

8条回答
  •  被撕碎了的回忆
    2021-02-06 22:35

    For my purpose, I needed to generalize Answer #2 a little bit. Here is the same function, taking Object as argument, instead of String:

    private String nullToEmpty(Object obj) {
        return obj == null ? "" : obj.toString();
    }
    

提交回复
热议问题