title: Java: Does "==" only check for reference to an object?
body: <p>So I was taught that “==”  only checks whether they are the same object and “equals()” checks the values of the objects.</p>
  
  <p>But for Strings, I found that “==” also checks for values. For example:-</p>
  
  <pre><code>    String x = "apple";
      String y = "orange";
      x=y;
  
      if (x==y){
          System.out.println("yes");
      }else{
          System.out.println("no");
      }
  
  //OUTPUT: yes
  </code></pre>
  
  <p>or</p>
  
  <pre><code>String x = "apple";
  String y = "apple";
  y = "watermelon";
      if (x==y){
          System.out.println("yes");
      }else{
          System.out.println("no");
      }tem.out.println("no");
      //OUTPUT: no
  </code></pre>