Avoid printing the last comma

前端 未结 13 568
无人及你
无人及你 2020-12-03 14:58

I\'m trying to print this loop without the last comma. I\'ve been Googling about this and from what i\'ve seen everything seems overcomplex for such a small problem. Surely

13条回答
  •  暖寄归人
    2020-12-03 15:29

    Found another simple way using regex:

    String str = "abc, xyz, 123, ";
    str = str.replaceAll(", $", "");
    System.out.println(str);  // "abc, xyz, 123"
    

提交回复
热议问题