I want to get specific lines of data from a text file using arraylist. (more context: student details are stored in Student.txt. if i have to update a specific student, i want to get that student's line from text file into an arraylist in order to edit it)
Text file looks like this (ID, Name, Degreelevel, Email, Conatctno : courses);
A30, sarah, sarah@gmail.com, +64732 ; Computer Science, Cyber Security, Digital Media
A45,zaha, zaha@gmail.com, +3683: Software Engineering
My code prints all the data in the text file into the arraylist.
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
ArrayList<String> lines = new ArrayList<>();
String line = reader.readLine();
while (line != null)
{
lines.add(line);
line = reader.readLine();
}
reader.close();
System.out.println(lines);
}
current output:[ID, Name, Degreelevel, Email, Conatctno : courses, A30, sarah, sarah@gmail.com, +64732 ; Computer Science, Cyber Security, Digital Media, A45,zaha, zaha@gmail.com, +3683: Software Engineering]
So how can i search a specific student ID and input only that line into arraylist. Any hint helps. Thank you.