Remove trailing comma from comma-separated string

前端 未结 16 939
生来不讨喜
生来不讨喜 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条回答
  •  余生分开走
    2020-12-04 21:50

    For more than one commas

                String names = "Hello,World,,,";
        System.out.println(names.replaceAll("(,)*$", ""));
    

    Output: Hello,World

提交回复
热议问题