Student asking for help.
I have a CSV file in the format (studentID,lastName,firstName,finalMark,finalGrade). I am trying to read this into a List of type Student / ArrayList of type Student - trying to add each line as a new Student. I have a Student class implementing Comparable for sorting the file. This Student class has these five (studentID,lastName,firstName,finalMark,finalGrade) as the Constructor.
Can someone please demonstrate/show me, through code and/or explanation, how to read from the file, into the List using FileReader and BufferedReader or (second preference) Scanner.
public static ArrayList <String> readAllLinesFromFile(String path) throws IOException {
// System.out.println("Cannot locate input file");
ArrayList<String> studentList = new ArrayList<String>();
FileReader fileReader = new FileReader("Question4unorderedList.csv");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line = null;
while((line = bufferedReader.readLine())!=null) {
studentList.add(line);
}
bufferedReader.close();
return studentList;
}
So I can create an ArrayList of type String. But how can I convert/parse/translate this ArrayList of Strings into a List or ArrayList of Student (my Student Class Constructor details are above).
Thanks for your help.