日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

深入理解Java原始数据类型和包装类关于==和equals的比较

發布時間:2025/3/20 java 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深入理解Java原始数据类型和包装类关于==和equals的比较 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.運算符 ==

對于六大Java數值類原始數據類型,==比較的是數值

對于六大Java原始數據類型對應的包裝類,==比較的是內存地址

2.equals()

equals()方法只有對象才有,所以我們討論一下原始數值類型的包裝在的equals()方法吧!

對于六大Java原始數據類型對應的包裝類,equals都是比較值。

有源碼為證如下所示:

Byte類

Short類

Integer類

Long類

Double類

/*** Compares this object against the specified object. The result* is {@code true} if and only if the argument is not* {@code null} and is a {@code Double} object that* represents a {@code double} that has the same value as the* {@code double} represented by this object. For this* purpose, two {@code double} values are considered to be* the same if and only if the method {@link* #doubleToLongBits(double)} returns the identical* {@code long} value when applied to each.** <p>Note that in most cases, for two instances of class* {@code Double}, {@code d1} and {@code d2}, the* value of {@code d1.equals(d2)} is {@code true} if and* only if** <blockquote>* {@code d1.doubleValue() == d2.doubleValue()}* </blockquote>** <p>also has the value {@code true}. However, there are two* exceptions:* <ul>* <li>If {@code d1} and {@code d2} both represent* {@code Double.NaN}, then the {@code equals} method* returns {@code true}, even though* {@code Double.NaN==Double.NaN} has the value* {@code false}.* <li>If {@code d1} represents {@code +0.0} while* {@code d2} represents {@code -0.0}, or vice versa,* the {@code equal} test has the value {@code false},* even though {@code +0.0==-0.0} has the value {@code true}.* </ul>* This definition allows hash tables to operate properly.* @param obj the object to compare with.* @return {@code true} if the objects are the same;* {@code false} otherwise.* @see java.lang.Double#doubleToLongBits(double)*/public boolean equals(Object obj) {return (obj instanceof Double)&& (doubleToLongBits(((Double)obj).value) ==doubleToLongBits(value));}

Float類

/*** Compares this object against the specified object. The result* is {@code true} if and only if the argument is not* {@code null} and is a {@code Float} object that* represents a {@code float} with the same value as the* {@code float} represented by this object. For this* purpose, two {@code float} values are considered to be the* same if and only if the method {@link #floatToIntBits(float)}* returns the identical {@code int} value when applied to* each.** <p>Note that in most cases, for two instances of class* {@code Float}, {@code f1} and {@code f2}, the value* of {@code f1.equals(f2)} is {@code true} if and only if** <blockquote><pre>* f1.floatValue() == f2.floatValue()* </pre></blockquote>** <p>also has the value {@code true}. However, there are two exceptions:* <ul>* <li>If {@code f1} and {@code f2} both represent* {@code Float.NaN}, then the {@code equals} method returns* {@code true}, even though {@code Float.NaN==Float.NaN}* has the value {@code false}.* <li>If {@code f1} represents {@code +0.0f} while* {@code f2} represents {@code -0.0f}, or vice* versa, the {@code equal} test has the value* {@code false}, even though {@code 0.0f==-0.0f}* has the value {@code true}.* </ul>** This definition allows hash tables to operate properly.** @param obj the object to be compared* @return {@code true} if the objects are the same;* {@code false} otherwise.* @see java.lang.Float#floatToIntBits(float)*/public boolean equals(Object obj) {return (obj instanceof Float)&& (floatToIntBits(((Float)obj).value) == floatToIntBits(value));}

總結

以上是生活随笔為你收集整理的深入理解Java原始数据类型和包装类关于==和equals的比较的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩a级片| 成人av一区二区在线观看 | 欧美人与禽猛交乱配视频 | av加勒比| 三级网站在线看 | 色综合999 | 欧美又大粗又爽又黄大片视频 | 香蕉久久av一区二区三区 | 中文字幕在线观看免费高清 | 亚洲热在线 | 91视频播放 | 国产成人免费av一区二区午夜 | 亚洲精品影院在线 | 久草视频在线资源站 | 亚洲一区第一页 | 韩日av在线播放 | 向着小小的花蕾绽放 | 中文在线字幕av | 久久久wwww| 性工作者十日谈 | 鲁一鲁av| 最近中文字幕mv免费高清在线 | 亚欧精品在线 | 欧美激情综合色综合啪啪五月 | 欧美大片www | 国产精品二区在线 | 大香伊人 | 久久综合综合久久 | 久久这里只有精品6 | 国产人妻777人伦精品hd | 国产日韩欧美在线观看视频 | 国产一区av在线 | 美女av网 | 99国产精品国产免费观看 | 国产天堂av在线 | 中文在线中文资源 | 人妻在线一区二区三区 | 国产一区亚洲二区 | 狠狠操中文字幕 | 欧美456 | 亚洲成人免费在线 | 潘金莲性xxxxhd| 亚洲视频在线播放免费 | 寂寞人妻瑜伽被教练日 | 亚洲精品在线观看av | 亚洲图片一区二区 | 超碰国产在线 | 热re99久久精品国产99热 | 三级国产在线观看 | 精品人妻一区二区色欲产成人 | 人妻少妇一区 | 黄色字幕网 | 亚洲精品天堂成人片av在线播放 | 精品少妇人妻av免费久久久 | 亚洲爱视频 | 伊人春色网站 | 日本羞羞网站 | 亚洲一区二区三 | 国产精品国产三级国产Av车上的 | 成人午夜激情网 | 成人免费无码大片a毛片 | 韩国三级中文字幕hd久久精品 | 欧美成人黑人xx视频免费观看 | 国产欧美一区二区三区鸳鸯浴 | 神秘电影永久入口 | 亚洲国产剧情在线观看 | 7777av| 国产美女性生活 | 欧美国产精品一二三 | 青草国产| 欧美成人黄色小说 | 亚洲欧美日韩一区二区三区四区 | 流白浆视频 | gav成人| 日本福利社| 亚洲29p| 蜜桃av噜噜一区二区三区小说 | 草久久免费视频 | 欧美a级肉欲大片xxx | 欧美性生活免费视频 | 色哟哟中文字幕 | 欧美精选一区二区 | 你懂的成人| 无码少妇精品一区二区免费动态 | 亚洲人成电影在线播放 | 1024国产视频 | 中文字幕日韩三级 | 国产精品18久久久久久vr下载 | 女同性做爰全过程 | 亚洲精品天堂网 | av毛片在线| 久操伊人 | 国自产拍偷拍精品啪啪一区二区 | 两个女人互添下身爱爱 | 波多野在线| 精品国产一区二区三区在线观看 | 黄色网址链接 | 蜜桃成熟时李丽珍国语 | 人妻无码一区二区三区免费 |