当前位置:网站首页>Integer常量池的理解
Integer常量池的理解
2022-07-21 05:17:00 【吧唧!】
方法一存值:采用Integer类的(常量池)缓存池(-128-127),超过范围,将会新创建空间
Integer x=21;
Integer x1=21;
System.out.println(x1==x);//内存地址比较,返回true
Integer y=133;
Integer y1=133;//超过了常量池(-128~127)的范围
System.out.println(y1==y);//内存地址比较,返回false
方法二存值: 采用Integer类的缓存池(-128-127)
//创建值在缓存池范围,则存入缓存池,超过则new新的空间
Integer x2=Integer.valueOf(12);
Integer x3=Integer.valueOf("12");//valueOf()是类型转换
System.out.println(x2==x3 );//内存地址的比较
方法三存值:采用Integer构造方法存值,创建了新对象,所以内存地址不同
Integer x4=new Integer(13);//Integer整型构造方法
Integer x5=new Integer("13");//字符串构造方法(字符串里只能含有数字)
System.out.println(x4==x5);//有new关键字创建,所以内存地址一定不相等
当采用 Integer构造方法存值,尽管存的值范围在常量池的范围内,也会开辟新的内存空间,内存地址一定不相同
边栏推荐
猜你喜欢
Wechat team sharing: how does the wechat background do not crash under massive concurrent requests
Im development technology sharing: talking about the best practice of offline messages and historical messages in IM system
OK the telephone system rules configured in the outbound call center
OSPF packet and interface network type
栈模拟队列
What are the ways to build a call center? Is okcc's manual outbound call suitable for your enterprise?
阿里IM技术分享(七):闲鱼IM的在线、离线聊天数据同步机制优化实践
Excel文件的解析
代码修改模型的渐隐和渐现
HCIP第一天作业
随机推荐
Decryption of social software red envelope technology (12): technical design and practice behind decryption of Tiktok Spring Festival red envelopes
How to use xswitch's built-in offline ASR and TTS
OSPF的优化
MySql the first
Connect with Tencent corporate email (authorize login free, obtain the number of unread emails)
windows mysql 5.7+ 修改表名大小写敏感属性
What are the types of call center telephone customer service system
Special topic on long connection Gateway Technology (VIII): evolution of microservice based API gateway in station B from 0 to 1
OSPF路由回馈及策略
GRE,MGRE
HCIA考核
OK the telephone system rules configured in the outbound call center
OSI参考模型总结
背面剔除|无剔除模式与透明物体的绘制
How to simulate stack with array (super simple code)
搭建呼叫中心有什么方式,OKCC人工外呼适合你的企业吗?
MySql the first
unity 粒子特效从相机外进入相机 应该是激活状态结果没有播放
Directx11-- window initialization (Win32)
What is SIP Protocol?