Ok, so I have a basic understanding of how to parse a csv file. My CSV basically looks like this:
I am using this code to read the csv file:date,name,weeks,cost
2012,steve,10,4000
2012,mike,8,2000
2011,cindy,15,5500
public void readCSV() { try { BufferedReader CSVFile = new BufferedReader(new FileReader("list.csv")); // Read first line. // The while checks to see if the data is null. If // it is, we've hit the end of the file. If not, // process the data. String dataRow = CSVFile.readLine(); while (dataRow != null){ String[] dataArray = dataRow.split(","); for (String item:dataArray) { System.out.print(item + "\t"); } System.out.println(); dataRow = CSVFile.readLine(); } CSVFile.close(); System.out.println(); } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } }
Okay, so the code reads line by line, if there is data on the line, it adds it to the string array, then prints out that string array.
Now here's my question:
Would it be possible to add each individual entry of the csv file to a place in an array list. For example, could I create some arraylist named "list" and add each piece of data to it one by one? So that "date" would be at index 0, "name" would be at index 1, etc.