Taking out elements from a matrix thus reducing its dimension
Hi,
I have written a program in Java2 which reads a txt file and stores each line of the file in a matrix called lines[]. Now what I want to do is to read through this matrix and take out some of its elements thus reducing its dimension. For example some of the lines in my file start with // which means that they are comments and I want to exclude those from my matrix. Some other lines are blank and I also want to exclude them. To make it more clear I give the example below:
I have the input.txt file which is as follows
Quote:
// This is a comment
234
44
// This is also a comment
werg
bf
34r2
dfv
// End of file
My code is:
Code:
int numLines=0;
scanLines = new Scanner(new BufferedReader(new FileReader("input.txt")));
scanLines.useDelimiter("\n");
while (scanLines.hasNext()) {
lines[numLines]=scanLines.next().trim();
numLines++;
}
Now the matrix created is:
lines[// This is a comment, 234, 44, // This is also a comment, werg, bf, , 34r2, dfv, // End of file]
which has a dimension of 10. I want to exlude the lines which start with // and the ones that are blank and end up with the matrix:
lines[234, 44, werg, bf, 34r2, dfv,]
which has a dimension of 6.
Any ideas??