title: How to terminate Scanner when input is complete?
body: <pre><code>public static void main(String[] args) {
  
          Scanner scan = new Scanner(System.in);
          try {
              while (scan.hasNextLine()){
  
                  String line = scan.nextLine().toLowerCase();
                  System.out.println(line);   
              }
  
          } finally {
              scan.close();
          }
      }
  </code></pre>
  
  <p>Just wondering how I can terminate the program after I have completed entering the inputs?
  As the scanner would still continue after several "Enter" assuming I am going to continue entering inputs...
  I tried:</p>
  
  <pre><code>if (scan.nextLine() == null) System.exit(0);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>if (scan.nextLine() == "") System.exit(0);  
  </code></pre>
  
  <p>They did not work.... The program continues and messes with the original intention,</p>