“==”和equals的区别

上传人:啧**** 文档编号:301817941 上传时间:2022-05-31 格式:DOCX 页数:1 大小:15.50KB
返回 下载 相关 举报
“==”和equals的区别_第1页
第1页 / 共1页
亲,该文档总共1页,全部预览完了,如果喜欢就下载吧!
资源描述

《“==”和equals的区别》由会员分享,可在线阅读,更多相关《“==”和equals的区别(1页珍藏版)》请在金锄头文库上搜索。

1、WORD(可编辑版本)“=”和equals的区别 Integer s1 = 123;Integer s2 = 123;Integer s3 = new Integer(123);Integer s4 = new Integer(123);System.out.println(s1.equals(s2);/trueSystem.out.println(s1=s2);/trueSystem.out.println(s3=s4);/falseSystem.out.println(s3.equals(s4);/trueSystem.out.println(s1=s3);/falseSystem.out

2、.println(s1.equals(s3);/true 可是假如是 Integer s1 = 123;int i =123;Integer s3 = new Integer(123);System.out.println(s1.equals(i);/trueSystem.out.println(s1=i);/trueSystem.out.println(s3=i);/ture 咱们会发觉Integer定义的和int定义的无论是通过equals比较依旧是“=”比较都为true,这是由于包装类和他们的基本数据类型比较和运算的时辰会有自动拆箱机制,将Integer自动拆箱成int。 假如有什么不对的地方盼望各位网友指出 1

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 商业计划书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号