从Java8开始,可以使用String.join()
.
String.join(", ", new String[]{"Hello", "World", "!"})
生成:
Hello, World, !
Otherwise, Apache Commons Lang has a StringUtils
class which has a join
function which will join arrays together to make a String
.
例如:
StringUtils.join(new String[] {"Hello", "World", "!"}, ", ")
生成以下String
:
Hello, World, !