I have a while loop which detects if sc.hasNext() is true and takes in the list of inputs typed, adding it to the list textEditor one by one.
while (sc.hasNext()) {
String line = sc.nextLine();
if (!(line.isEmpty())){
textEditor.addString(line);
}
}
sc.close();
textEditor.printAll();
}
}
However, when I type in a list of strings e.g.
oneword
two words
Hello World
hello World
the loop does not stop and the method printAll() is not called. How do I break out of the while loop?