title: How to compare two Booleans in Java?
body: <p>I have to compare two <code>Boolean</code> wrappers with each other. As a result I want to know if they are equal or not.</p>
  
  <p>This is what I came up with:</p>
  
  <pre><code>public static boolean areEqual(final Boolean a, final Boolean b) {
      if (a == b) {
          return true;
      }
  
      if (a != null &amp;&amp; b != null) {
          return a.booleanValue() == b.booleanValue();
      }
  
      return false;
  }
  </code></pre>
  
  <p>Is there a better and/or shorter way to correctly compare two <code>Boolean</code> wrappers for equality?</p>
  
  <p>First I wanted to use <code>Object.equals()</code> or <code>Boolean.compareTo()</code> but both ways could end up in a <code>NullPointerException</code>, right?
  Maybe there is something that I don't see here, that's why I'm asking.</p>