JAVA - Why a == "1" returns false
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/7128775/string-is-not-equal-to-string">String is not equal to string?</a><br>
  <a href="http://stackoverflow.com/questions/9698260/what-makes-reference-comparison-work-for-some-strings-in-java">What makes reference comparison (==) work for some strings in Java?</a>  </p>
</blockquote>



<p>can some one explain me following java code </p>

<pre><code>String a = "1";
if(a == "1") {
//print compare 1 is true;
} else { 
//print compare 1 is false;
}

if(a.equals("1")) {
//print compare 2 is true;
} else { 
//print compare 2 is false;
}
</code></pre>

<p>it results like </p>

<pre><code>compare 1 is false
compare 2 is true
</code></pre>

<p>Only explanation i have is that its comparing the memory address not the values itself. But i am not sure. can some please put a light on it. in .Net == operator is overloaded to compare contents of string. </p>
