title: How can I properly compare two Integers in Java?
body: <p>I know that if you compare a boxed primitive Integer with a constant such as:</p>
  <pre><code>Integer a = 4;
  if (a &lt; 5)
  </code></pre>
  <p><code>a</code> will automatically be unboxed and the comparison will work.</p>
  <p>However, what happens when you are comparing two boxed <code>Integers</code> and want to compare either equality or less than/greater than?</p>
  <pre><code>Integer a = 4;
  Integer b = 5;
  
  if (a == b)
  </code></pre>
  <p>Will the above code result in checking to see if they are the same object, or will it auto-unbox in that case?</p>
  <p>What about:</p>
  <pre><code>Integer a = 4;
  Integer b = 5;
  
  if (a &lt; b)
  </code></pre>
  <p>?</p>