Hi,
Just wondering if anyone has any example of reading data from a file and storing it into an uneven 2D array.
For example:
the file contains
[a,b,c]
[a,b,c,d]
[a,b,]
etc
I am able to do this with a complete "square" or matrix but when the columns aren't even I'm not sure how to do this.
Code below I initialised the array as 3 rows and 4 columns but my column can be less than that. How do I input the data into the matrix if column is only 2?
File file = new File("testing.txt");
String[][] list = new String[3][4];
try {
Scanner scanner = new Scanner(file).useDelimiter(",|\r");
for (int r=0; r < 3; r++)
{
for (int c=0; c <4; c++)
{
list[r][c] = scanner.next();
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
Please help!