文字配列を文字列配列に変換するにはどうすればよいですか?
例えば"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]);
}
}
}