I'm trying to scan a text file and place each line into an arraylist, and stop scanning when the next line is a '*', however, my arraylist is storing every 2nd line and I am not sure why.
Scanner scan = new Scanner(new File("src/p/input2.txt"));
ArrayList<String> words = new ArrayList<String>();
while(scan.hasNextLine()) {
if(scan.nextLine().equals("*"))
break;
words.add(scan.nextLine());
}
The textfile:
1
dip
lip
mad
map
maple
may
pad
pip
pod
pop
sap
sip
slice
slick
spice
stick
stock
*
spice stock
may pod
What is being stored in my arraylist:
[dip, mad, maple, pad, pod, sap, slice, spice, stock]