I want to parse an almost program. The program is consisted of two lines and it is shown below:
java.io.*;
java.lang.*;
I am using a library, which reads the whole program and splits it using the command
String[] words = sourceCode.split("[\\s+|\\W+]");
What it is produced by that is the following
words[0] = "Java"
words[1] = "io"
words[2] = ""
words[3] = ""
words[4] = ""
words[5] = ""
words[6] = Java
words[7] = "lang"
words[8] = ""
words[9] = ""
words[10] = ""
words[11] = ""
However, What I want is to break that program in lines first, and after that at a line's component. That is, I am using
String[] allLines = file1String.split("[\n]");
String[][] wordsOfALine =new String[allLines.length][];
for (int i=0;i<allLines.length;i++){
wordsOfALine[i] = allLines[i].split("[\\s+|\\W+]").clone();
}
However, what I am getting here is
wordsOfALine[0][0] = "Java"
wordsOfALine[0][1] = "io"
wordsOfALine[1][0] = "Java"
wordsOfALine[1][1] = "lang"
And therefore all the empty words have now disappeared. Do you know how I can bring them back? I need to be consistent with the library...
Thanks