StringJoiner简化分隔字符带来的处理

import java.util.StringJoiner;

public class StringJoinerDemo {

    public static void main(String[] args) {
        String[] names = {"A","B","C","D"};
        StringJoiner stringJoiner = new StringJoiner(",");
        for (String name : names){
            stringJoiner.add(name);
        }
        System.out.println(stringJoiner);
    }
}

结果:A,B,C,D

posted @ 2022-06-30 17:06  蔡徐坤1987  阅读(17)  评论(0编辑  收藏  举报