title: What is the cleanest way to compare an int with a potentially null Integer in Java?
body: <pre><code>Map&lt;String,Integer&gt; m;
  m = new TreeMap&lt;String,Integer&gt;();
  </code></pre>
  
  <p>Is it good practice to add the following cast just to avoid the null pointer exception when m.get() is null.</p>
  
  <pre><code>System.out.println( ((Integer) 8).equals( m.get("null") ) ); // returns false
  </code></pre>
  
  <p>Alternatively with a prior null check it starts to look a bit ugly.</p>
  
  <pre><code>System.out.println( m.contains("null") != null &amp;&amp; m.get("null").equals( 8 ) );
  </code></pre>
  
  <p>Is there a better way to write this? Thanks.</p>