title: Compare two objects in Java with possible null values
body: <p>I want to compare two strings for equality when either or both can be <code>null</code>.</p>
  <p>So, I can't simply call <code>.equals()</code> as it can contain <code>null</code> values.</p>
  <p>The code I have tried so far :</p>
  <pre><code>boolean compare(String str1, String str2) {
    return ((str1 == str2) || (str1 != null &amp;&amp; str1.equals(str2)));
  }
  </code></pre>
  <p>What will be the best way to check for all possible values including <code>null</code> ?</p>