Remove trailing comma from comma-separated string

前端 未结 16 918
生来不讨喜
生来不讨喜 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:40

    You can do something like this using 'Java 8'

    private static void appendNamesWithComma() {
        List namesList = Arrays.asList("test1", "tester2", "testers3", "t4");
        System.out.println(namesList.stream()
                                    .collect(Collectors.joining(", ")));
    
    }
    

提交回复
热议问题