String关于join()有两个重载的方法
- public static String join(CharSequence delimiter, CharSequence… elements)
作用:将elements用指定的字符串delimeter连接起来,返回这个新组成的字符串
使用举例:
String message = String.join("-", "Java", "is", "cool");
// message returned is: "Java-is-cool"
- public static String join(CharSequence delimiter, Iterable extends CharSequence> elements)
作用:将elements用指定的字符串delimeter连接起来,返回这个新组成的字符串
使用举例:
Liststrings = List.of("Java", "is", "cool"); String message = String.join(" ", strings); // message returned is: "Java is cool" Set strings = new linkedHashSet<>(List.of("Java", "is", "very", "cool")); String message = String.join("-", strings); // message returned is: "Java-is-very-cool"
参考资料:
[1] jdk15.0.2



