如何将 char 数组转换为字符串数组?
例如"Text not text" → "Text not text" as char array → "Text" "not" "text"
我知道怎么做"Text not text" → "Text not text"
,但不知道怎么做
"Text not text" as char array → "Text" "not" "text"
这是代码示例,但它不起作用
public class main {
public static void main(String[] args) {
StringBuffer inString = new StringBuffer("text not text");
int n = inString.toString().replaceAll("[^a-zA-ZА-Я а-я]", "")
.split(" ").length;
char[] chList = inString.toString().toCharArray();
System.out.print("Text splited by chars - ");
for (int i = 0; i < chList.length; i++) {
System.out.print(chList[i] + " ");
}
System.out.println();
String[] temp = new String[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < chList.length; j++) {
if (chList[j] != ' ') {
temp[i] = new String(chList);
}
}
System.out.println(temp[i]);
}
}
}