对于基本数据类型而言。int a = 10;int b = 10; a==b 返回true.对于引用类型而言String c = new String("10");String d = new String("10");c == d 返回false,c.equals(d)返回true.
Compares this string to the specified object. The result is true
if and only if the argument is not null
and is a String
object that represents the same sequence of characters as this object.
Compares this object to the specified object. The result is true
if and only if the argument is not null
and is an Integer
object that contains the same int
value as this object.
两个对象的hashCode相同,equal方法返回true.
对于两个对象而言,==比较两个引用的地址是否相同。