title: While loop in Java, string comparison does not work
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java">How do I compare strings in Java?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm working on a small program that asks for your name using a <code>Scanner</code>.  If you enter blankstring, then I would like the console to display a message.</p>
  
  <p>Here's what I tried doing:</p>
  
  <pre><code>import java.util.Scanner; 
  public class Adventure
  {  
      public static void main(String[] args) 
      {      
          Scanner myScan = new Scanner (System.in);                             
          System.out.println("What's your name?");                                 
          String name = myScan.nextLine();
  
          while (!(name == ""))   //Always returns false.
          {
              System.out.println("That's not your name. Please try again.");
              name = myScan.nextLine();
          }
  
          System.out.println("It's a pleasure to meet you, " + name + ".");
      }
  }
  </code></pre>
  
  <p>The code never enters the while loop.  Why?</p>