title: String answer1 = "yes"; if (answer1 == "yes") gives false. Why?
body: <pre><code>import java.util.Scanner;
  
  public class NewClass {
      public static void main(String[] args){
  
          Scanner scanner = new Scanner(System.in);
  
          System.out.println("Enter your name");
          String name = scanner.nextLine();
          System.out.println("Is "+ name + " really your name?");
          String answer1 = scanner.nextLine();
          if (answer1 == "yes"){
          System.out.println("Alright ");
          }else  {System.out.println("Liar!");
      }
      }
  }
  </code></pre>
  
  <p>It outputs <code>Liar!</code> even though I typed <code>yes</code>, so that <code>answer1</code> equals <code>yes</code>. Why?</p>