StringJoiner
public static void main(String[] args) { //值依次是分割符,前缀,后缀 StringJoiner joiner = new StringJoiner(",","[","]"); joiner.add("张三").add("李四"); //结果:[张三,李四] System.out.println(joiner); }