I have a java method to read in a file into an arraylist, then print the file. T
ID: 3530435 • Letter: I
Question
I have a java method to read in a file into an arraylist, then print the file. The file reads in like so: Frodo Baggins 1.0 2.0 3.0 4.5 6.6 Bilbo Baggins 1.0 2.0 3.0 6.0 6.9 and so on.. When I print the arraylist it prints like so: Frodo Baggins, 1.0, 2.0, 3.0, 4.5, 6.6, Bilbo Baggins, 1.0, 2.0, 3.0, 6.0, and so on until the list ends all on one line? How do I get this to print like so: Frodo Baggins, 1.0, 2.0, 3.0, 4.5, 6.6 Bilbo Baggins, 1.0, 2.0, 3.0, 6.0 next name next name????? Current Code: FileReader ReadFile=new FileReader("File.txt"); BufferedReader ReadFileBuffer=new BufferedReader(ReadFile); ArrayList StudentwithGrades=new ArrayList(); String currentLine; int lineCounter=0; while((currentLine=ReadFileBuffer.readLine())!=null) { StudentwithGrades.add(currentLine); lineCounter++; } ReadFileBuffer.close(); System.out.println(StudentwithGrades);Explanation / Answer
Hi,
Add the below line in the WHILE loop as a last statement to get the name next name.
System.out.println(" ");
Hope, it gives desired output.
Thanks,
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.