title: Java substring.equals versus ==
body: <p>Using the standard loop, I compared a substring to a string value like this:</p>
  
  <pre><code>if (str.substring(i, i+3) == "dog" ) dogcount++;
  </code></pre>
  
  <p>and it broke the iteration. After the first increment, no further instances of "dog" would be detected.</p>
  
  <p>So I used substring.equals, and that worked:</p>
  
  <pre><code>if (str.substring(i, i+3).equals("dog")) dogcount++;
  </code></pre>
  
  <p>My question is, why? Just seeking better understand, thx.</p>