public class ByteArr {
public static void main(String[] args){
Byte[] a = {(byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00};
Byte[] b = {(byte)0x
why a[] doesn't equals b[]?
Because equals
function really called on Byte[]
or byte[]
is Object.equals(Object obj)
. This functions only compares object identify , don't compare the contents of the array.
There's a faster way to do that:
Arrays.hashCode(arr1) == Arrays.hashCode(arr2)
Java byte compare,
public static boolean equals(byte[] a, byte[] a2) {
if (a == a2)
return true;
if (a == null || a2 == null)
return false;
int length = a.length;
if (a2.length != length)
return false;
for (int i = 0; i < length; i++)
if (a[i] != a2[i])
return false;
return true;
}