title: How do I check if the enter key has been pressed in a Scanner?
body: <p>First, I tried:</p>
  
  <pre><code>while (!(in.nextLine().equals("")))
      arrayList.add(in.nextInt());
  </code></pre>
  
  <p>This doesn't work out too well at all for me. Instead, I tried:</p>
  
  <pre><code>while (in.hasNextint())
      arrayList.add(in.nextInt());
  </code></pre>
  
  <p>Basically I type numbers separated by whitespace and then enter some letter and press enter. This works perfectly in IDEs. However, if I try to compile and run it using the command prompt it throws an error in my face: InputMismatchException. Finally, I tried:</p>
  
  <pre><code>while (in.nextLine() != null) 
      arrayList.add(in.nextInt());
  </code></pre>
  
  <p>And that did not work(!) Any ideas?</p>