Remove trailing comma from comma-separated string

前端 未结 16 922
生来不讨喜
生来不讨喜 2020-12-04 21:37

I got String from the database which have multiple commas (,) . I want to remove the last comma but I can\'t really find a simple way of doing it.

16条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 21:59

    You can use this:

    String abc = "kushalhs , mayurvm , narendrabz ,";
    String a = abc.substring(0, abc.lastIndexOf(","));
    

提交回复
热议问题