当前位置:编程学习 > JAVA >>

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

对于基本数据类型而言。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.

对于两个对象而言,==比较两个引用的地址是否相同。 


摘自  行者无涯
补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,