StringJoiner 小练习之二

`import java.util.StringJoiner;
public class Demo13{
public static void main(String[] args) {

	String[] names = {"Bob", "Alice", "Grace"};
	
	
	//数组元素间用分隔符"," 打印出来Hello Bob, Alice, Grace !
	
	//这是一个重载构造器,第一个参数表示分隔符,第二个参数表示开头,第三个参数表示结尾

	StringJoiner sj = new StringJoiner(", ","Hello "," !");
	
	for(String name:names){
		sj.add(name);
	}
	
	System.out.println(sj.toString());

}

}`

posted @ 2020-12-23 19:06  dog_IT  阅读(78)  评论(0编辑  收藏  举报