title: Why doesn’t == work on String?
body: <p>I just started Java programming. I love it so far, but I have been stuck on this problem for a while.</p>
  
  <p>When I run this code, whenever I type in “boy” it will just respond with <code>GIRL</code>:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class ifstatementgirlorboy {
      public static void main(String args[]) {
          System.out.println("Are you a boy or a girl?");
          Scanner input = new Scanner(System.in);
          String gender = input.nextLine();
  
          if(gender=="boy") { 
              System.out.println("BOY");
          } 
          else { 
              System.out.println("GIRL"); 
          }
      }
  }
  </code></pre>
  
  <p>Why?</p>