如何比较两个byte数组一样吗

2025-05-09 01:14:36
推荐回答(1个)
回答1:

==和equals()方法的区别
==是比较基本类型的值(在栈中存放)是否相等,
而equals()是比较两个引用对象的内容(在堆中存放)是否完全一样。
看看这个例子:
public class Test11
{
public static void main(String[] args)
{
String s1=new String("qq");
String s2=new String("qq");
if(s1.equals(s2))
System.out.println("true");
else
System.out.println("false");

byte[]t1=new byte[1];
byte[]t2=new byte[1];

t1[0]='a';//这两句赋值 要与不要 结果都一样的
t2[0]='a';
if(t1.equals(t2))
System.out.println("true");
else
System.out.println("false");

}
}