public class Test1 {
public static void main(String[] args) {
System.out.println("Give me a word: ");
Scanner console = new Scanner(System.in);
ArrayList<String> arr = new ArrayList<>();
boolean found = true;
while (console.hasNextLine() && found) {
String line = console.nextLine();
if (line.equals("")) {
found = false;
} else {
arr.add(line);
}
}
System.out.println("You said: ");
for (int index = 0; index < arr.size(); index++) {
System.out.println(arr.get(index));
}
}
}
I'd like to print what user typed in whenever the user types enter twice, however this requires three enters to be inputted for some reason. When I remove the console.hasNextLine statement in while loop's condition, it works perfectly fine. Why is this the case?