title: How to check if a BigInteger is null
body: <p>I have a code which may assign null to a BigInteger. I need to check if it is null or not.</p>
  
  <p>I've tried the following things, and they do not work:</p>
  
  <ol>
  <li><p><code>==</code> will just check the reference, not the value.</p>
  
  <pre><code>BigInteger x = BigInteger.ONE;
  
  if(x== null)
  {
      System.out.println( x );
  }
  </code></pre></li>
  </ol>
  
  <p>Output of above is it prints x. (Somehow the boolean condition is satisfied, even though x is not null).</p>
  
  <ol start="2">
  <li><p>Following gives NullPointerException upon comparing</p>
  
  <pre><code>BigInteger x = BigInteger.ONE;
  BigInteger myNull = null;
  
  if(x.compareTo(myNull) == 0 )
  {
      System.out.println( x );
  }
  </code></pre></li>
  <li><p>Another NPE:</p>
  
  <pre><code>BigInteger x = BigInteger.ONE;
  
  if(x.compareTo(null) == 0)
  {
      System.out.println( x );
  }
  </code></pre></li>
  </ol>
  
  <p>How do I check if a BigInteger is null properly?</p>