title: Compare two arrays of primitives in Java?
body: <p>I know about Arrays.deepEquals(Object[], Object[]) but this doesn't work for primitive types (due limitations of arrays and autoboxing, see <a href="https://stackoverflow.com/questions/517751/java-generic-method-but-array-of-primitive-data-types-does-not-autobox">this related post</a>).</p>
  
  <p>With that in mind, is this the most efficient approach?</p>
  
  <pre><code>boolean byteArrayEquals(byte[] a, byte[] b) {
      if (a == null &amp;&amp; b == null)
          return true;
  
      if (a == null || b == null)
          return false;
  
      if (a.length != b.length)
          return false;
  
      for (int i = 0; i &lt; a.length; i++) {
          if (a[i] != b[i])
              return false;
      }
      return true;
  }
  </code></pre>