title: Java using scanner enter key pressed
body: <p>I am programming using Java.<br>
  I am trying write code which can recognize if the user presses the enter key in a <strong>console based program.</strong></p>
  
  <p>How can I do this using java. I have been told that this can be done using either Scanner or, buffered input reader. I do not understand(or know how to use) buffered input reader.</p>
  
  <p>I tried to do do this using scanner but after pressing enter twice the program terminates, and it doesn't work</p>
  
  <pre><code>    Scanner readinput = new Scanner(System.in);
  
      String enterkey = "Hola";
      System.out.print(enterkey);
  
  
      enterkey = readinput.nextLine();
       System.out.print(enterkey);
  
      if(enterkey == ""){
  
          System.out.println("It works!");
  </code></pre>
  
  <p>Thanks   </p>
  
  <p>-- edit --
  the following code works using the <code>equals</code> method for the string instead of <code>==</code></p>
  
  <pre><code>    Scanner readinput = new Scanner(System.in);
  
      String enterkey = "Hola";
      System.out.print(enterkey);
  
  
      enterkey = readinput.nextLine();
       System.out.print(enterkey);
  
      if(enterkey.equals("")){
  
          System.out.println("It works!");
  </code></pre>
  
  <p>how can this be done, and what are the pros to doing this using the buffered input reader?</p>