How can I can convert char array to string array?
For example "Text not text" → "Text not text" as char array → "Text" "not" "text"
I understand how to "Text not text" → "Text not text"
, but dont know how to
"Text not text" as char array → "Text" "not" "text"
Here is code example, but it does not work
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]);
}
}
}
String[n]
? Do you want a String for each char? or String as number of spaces +1? – whoAmI Apr 22 at 11:50