I am looking for a way to read a tab delimited file of baseball stats into a two dimensional arraylist. I'm using a scanner to read the file, but I can't think of how to read just one line into an array list, stopping at the line break, then read the next line into the next arraylist.
This is my first time trying to create a multidimensional arraylist, and I thought it would be much the same as reading multidimensional arrays. I was clearly mistaken.
public static ArrayList dataRead(String fileloc) throws FileNotFoundException {
ArrayList array = new ArrayList<ArrayList>();
Scanner s = new Scanner(new File(fileloc)).useDelimiter("\t");
ArrayList<String> rows = new ArrayList<String>();
ArrayList cols = new ArrayList();
while(s.nextLine() != null) {
cols.add(s.next());
}
return array;
}
This is my code as of now. Would it be a better choice to read each line into a string, delimited by returns, then read each string into an appropriate arraylist?