0
点赞
收藏
分享

微信扫一扫

优雅的字符串拼接去掉逗号方式

云岭逸人 2022-01-25 阅读 75
java

talk is cheep!show you the code!!

public static void main(String[] args) {
        List<String> appends = new ArrayList<>();
        appends.add("aaa");
        appends.add("bbb");
        appends.add("ccc");
        StringBuilder content = new StringBuilder();
        int size = appends.size();
        if (!CollectionUtils.isEmpty(appends)) {
            for (int i = 0; i < size; i++) {
                content.append(appends.get(i));
                // 最后一个不加逗号
                if (size - 1 == i) {
                    break;
                }
                content.append(",");
            }
        }
        System.out.println(content);
    }
举报

相关推荐

0 条评论