split() 将字符串拆分成数组

join() 将数组合并

参数为分隔符

两套代码

1
2
3
4
5
6
#JavaScript
var str = "ruben";
var array = str.split('');
array.forEach(s => console.log(s));
str = array.join('');
console.log(str);

以及

1
2
3
4
5
6
7
8
//java
String str = "ruben";
String[] array = str.split("");
for (String s : array) {
System.out.println(s);
}
str = String.join("", array);
System.out.println(str);