StringBuilder append() and null values

后端 未结 8 932
借酒劲吻你
借酒劲吻你 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:33

    Null check as @Shynthriir has mentioned is the simplest most efficient way (AFAIK) to get around the problem.

    I would however strongly recommend initiating strings to an empty string String str = ""; instead, which would save you a lot of headache in a more complex programming effort.

提交回复
热议问题