认识Integer

public class TestDemo{

public void main(String[] args){

//对象保存在堆中

Integer i =new Integer(5);

Integer j = new Integer(5);

System.out.println(i==j);//false 内存地址

System.out.println(i.equals(j));//true 内存里保存的数据

//对象保存在常量池中

Integer i =5; //超过127以后(128)源码中看到缓存了-128  ——127的数据

Integer j =5

System.out.println(i==j);//true                                //false

System.out.println(i.equals(j));//true                     //true

}

}

启动时已经缓存好了

 Boolean Byte 全部缓存

Character <=127  缓存   

Short Integer Long 都-128 ——127缓存     

Float Double 无缓存 (不精确)


String s1="hello";

String s2="hello;

System.out.println(s1==s2);//true

String s3=new String("hello");//实际在内存存了6个还有/0.字符串的结束标志

String s4="hello";

System.out.println(s3==s4);//false

在堆中heap中有String pool(缓存池)第一句代码执行时,先去缓存池找有没有hello,没有再创建。

当第一次遇到时会缓存

String pool

String的缓存

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值