灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2511回复:0

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

楼主#
更多 发布于:2012-09-08 09:37


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

返回顶部