The method should read the contents of a file line by line and add each line to the array list. It should end once it reaches a solitary "." (period) or no more lines.
The problem is that I can not figure a way to check the contents of the next line without skipping lines since I am using nextLine numerous times. I am limited to the use of hasNext and nextLine.
public static ArrayList<String> getList(Scanner in) {
ArrayList<String> list = new ArrayList<String>();
while(in.hasNext() && !in.nextLine().equals("."))
{list.add(in.nextLine());}
return list;}
As written the output will skip lines to output lines 2, 4, 6 etc when I need it to output 1,2,3,4 etc.
I am sure I am simply not seeing the way to solve the issue but any hints specifically on how to get it working by reformatting what I have with the methods listed are appreciated.