equals和==的区别
变量:==用于比较变量的值是否相等
例如 int a=1; int b=2; 比较结果返回false
int a=1; int b=1; 比较结果返回true
对象:==用于比较对象的内存地址是否相同
例如:String a=new String("hello"); String b=new String("hello"); 比较结果返回true,因为内容相同。
变量:==用于比较变量的值是否相等
例如 int a=1; int b=2; 比较结果返回false
int a=1; int b=1; 比较结果返回true
对象:==用于比较对象的内存地址是否相同
例如:Person a=new Person(); Person b=new Person(); 比较结果返回false,因为创建了两个不同的对象
equals用于比较对象的内容是否相同例如:String a=new String("hello"); String b=new String("hello"); 比较结果返回true,因为内容相同。