当前位置:网站首页>integer 和==比较
integer 和==比较
2022-07-23 16:30:00 【thoughtCodes】
项目场景:
提示:这里简述项目相关背景:
a bittler loser, 没有在问题上耗时
对了还有一个问题这里除了好像的问题那就是integer 的比较方式:
问题描述
提示:这里描述项目中遇到的问题:
我的方式是:是这种的方式是:结果报错了:
Integer a1 = new Integer(1);
System.out.println(a1.toString().equals("1")); //字符串的比较
System.out.println(a1.equals("1")); //inteer 的比较:
原因分析:
提示:这里填写问题的分析:
public boolean equals(Object obj) {
if (obj instanceof Integer) {
return value == ((Integer)obj).intValue();
}
return false;
}
可以看见是把对比的对象看是不是Integer类型的,是的话就转为int基本类型再用 == 比较,比较的就是数值了。所以来点特殊的。
源码的本质的比较的是看不能转换成int 类型否则是返回false.的。
但是
解决方案:
提示:这里填写该问题的具体解决方案:
查资料可以知道Integer有缓存数组,即-128<=value<=127,都从缓存数组中获取Integer对象。对于测试中的,q和w都是超过了缓存的值,因此都是new的新得对象,所以匹配不了。所以我们不难理解,Integer的“”方法是比较地址的。而Integer的equals方法则不会有这些问题,是直接字面上的比较。
因此使用Integer做比较的时候,的区分是否超过了缓存数组的区域。
大数字比较使用integer,小数据比较使用==.
边栏推荐
- PCL:多直線擬合(RANSAC)
- Major optimization of openim - Message loading on demand, consistent cache, uniapp Publishing
- Can self-study 3D modeling succeed? Can self-study lead to employment?
- As a senior 3D modeler, I give some suggestions to novice learning partners to use
- [whole process of game modeling model production] ZBrush weapon model production: Crossbow
- 使用kail破解wifi密码
- 【2018】【论文笔记】石墨烯场效应管及【1】——GFETs的种类和原理,GFETs特性,GFETs在太赫兹中的应用和原理
- ZigBee system development of Internet of things I (Introduction to ZigBee) [easy to understand]
- rhcsa笔记五
- The Little Schemer-周而复始之Y组合子由来
猜你喜欢

DDD:如何领用领域驱动设计来避免写流水账代码

Is it suitable for learning 3D modeling? You can't lose one of these five points

Spark 安装与启动

如何抓取新浪财经数据中心分析师评级数据?
![[whole process of game modeling model production] 3ds Max and ZBrush produce radio receivers](/img/c9/302a52d2c9f6fc3b5971e9a0ea55e6.png)
[whole process of game modeling model production] 3ds Max and ZBrush produce radio receivers

Jetty 服务器的 NIO 机制是如何导致堆外内存溢出的

B端市场复苏背后:谁站到台前?

Three things programmers want to do most | comics

Boss online replay: the mistake I made when training Dall · e

rhcsa笔记三
随机推荐
rhcsa笔记五
如何评估券商分析师预测股票涨跌的准确性?
Awk from introduction to earth (16) comprehensive case of awk
如何成为建模师?工业建模和游戏建模哪一个更加吃香?
OSI模型第一层:物理层,基石般的存在!
Simply understand why the first EVM equivalent zkevm polygon is fully betting
Block encryption mode ECB, CBC, PCBC, CFB, OFB, CTR
Alliance DAO创始人:100+Web3基础设施及Dapp创业清单
Behind the recovery of the B-END Market: who stands in front of the stage?
The little schemer - the origin of the y-zygote cycle
悲观锁和乐观锁
Rhcsa Notes 6
华为胖瘦AP切换方法
【2020】【论文笔记】相变材料与超表面——
Ali Er Mian: what is CAS?
自学3D建模能不能成功?自学能就业吗?
【2018】【论文笔记】石墨烯场效应管及【2】——石墨烯的制备、转移
次世代行业现状如何?90%转行建模师都在学习这套流程
我的创作纪念日
世界上最大的开源基金会 Apache 是如何运作的?