how to compare the Java Byte[] array?

后端 未结 15 2408
囚心锁ツ
囚心锁ツ 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 01:51

    Because neither == nor the equals() method of the array compare the contents; both only evaluate object identity (== always does, and equals() is not overwritten, so the version from Object is being used).

    For comparing the contents, use Arrays.equals().

提交回复
热议问题