how to compare the Java Byte[] array?

后端 未结 15 2360
囚心锁ツ
囚心锁ツ 2020-12-13 01:17
public class ByteArr {

    public static void main(String[] args){
        Byte[] a = {(byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00};
        Byte[] b = {(byte)0x         


        
15条回答
  •  粉色の甜心
    2020-12-13 02:08

    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;
        }
    

提交回复
热议问题