我只发现了这个,但它不起作用,如果有人帮助我,我将非常感激,因为我是 Java 新手,这让我很生气,哈哈:
public class ConcatenateStrings {
public static String concateLines(String[] s, String separator) {
String result = "";
if (s.length > 0) {
result = s[0]; // start with the first element
for (int i = 1; i < s.length; i++) {
StringBuilder sb = new StringBuilder(result);
sb.append(separator);
sb.append(s[i]);
result = sb.toString();
}
}
return result;
}
}