I'd like to implement Scanner termination when input is complete. As a termination I choose blank line - just enter key. However for some reason (unknown to me) below implementation doesn't work. Do you have any idea why? Or maybe you know better solution?
Scanner scanner = new Scanner(System.in);
while (!scanner.nextLine().startsWith("\n")) {
// code
}
// code after press just Enter
I tried also:
while (!scanner.nextLine().equals("\n"))
... or:
while (scanner.nextLine().isEmpty())
Nothing works...
PS. Some of you may think that I duplicate this topic: How to terminate Scanner when input is complete?
However I do it on purpose, because I'm asking now about specific implementation, not a general Scanner termination.