So I created a method that takes in a 2D char array that was originally from a text file and would end up outputting a string array. The only problem is the string.split()
method doesn't take into account new lines or empty lines and I need the string.length()
to be accurate to obtain a word count. Is there code that I am missing?
This is the code I have so far.
public static String[] textString(char[][] text) {
String string = "";
for (int i = 0; i < text.length; i++) {
for (int k = 0; k < text[i].length; k++) {
string += text[i][k];
}
string += "\n";
}
String[] stringA = string.split(" ");
return stringA;
}