goback add

java中equal()方法和==方法的区别

3203 点击·0 回帖
灯火互联
楼主


对于基本数据类型而言。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.
对于两个对象而言,==比较两个的地址是否相同。


喜欢0 评分0