title: Terminate scanner input
body: <p>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?</p>
  
  <pre><code>Scanner scanner = new Scanner(System.in);
  while (!scanner.nextLine().startsWith("\n")) {
       // code
  }
  // code after press just Enter
  </code></pre>
  
  <p>I tried also:</p>
  
  <pre><code>while (!scanner.nextLine().equals("\n")) 
  </code></pre>
  
  <p>... or:</p>
  
  <pre><code>while (scanner.nextLine().isEmpty())
  </code></pre>
  
  <p>Nothing works...</p>
  
  <p>PS. Some of you may think that I duplicate this topic:
  <a href="https://stackoverflow.com/questions/16206813/how-to-terminate-scanner-when-input-is-complete">How to terminate Scanner when input is complete?</a></p>
  
  <p>However I do it on purpose, because I'm asking now about specific implementation, not a general Scanner termination.</p>