compare string with equals method and ==
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java">How do I compare strings in Java?</a><br>
  <a href="http://stackoverflow.com/questions/767372/java-string-equals-versus">Java String.equals versus ==</a>  </p>
</blockquote>



<p>I am newbie Java programming and I have a little question about compare string with 
<code>equals</code> method and <code>==</code></p>

<p>Example 1: Doesn't work when get input from user but if it has set initial value it works fine.</p>

<pre><code>if(str1 == str2) 
 System.out.println("equal");
</code></pre>

<p>Example 2: always works</p>

<pre><code>if(str1.equals(str2))
 System.out.println("equal");
</code></pre>

<p>if I have to compare string which command can be used.</p>
