创建对象,添加元素:
import java.util.Scanner;
import java.util.StringJoiner;public class practice{public static void main(String[ ] args){StringJoiner sj = new StringJoiner("---");sj.add("aaa").add("bbb");System.out.println(sj);}
}
代码运行截图:
代码:
import java.util.Scanner;
import java.util.StringJoiner;public class practice{public static void main(String[ ] args){StringJoiner sj = new StringJoiner("---","[","]");sj.add("aaa").add("bbb").add("ccc");int len = sj.length();System.out.println(len);System.out.println(sj);String str = sj.toString();System.out.println(str);}
}
长度代表,最后打印出来的所有长度;
截图: