StringBuilder append() and null values

后端 未结 8 925
借酒劲吻你
借酒劲吻你 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 22:38

    In one line you can do:

    System.out.println(sb.append("Value: ").append((s==null)?"":s));
    

提交回复
热议问题