Java包装类

Java数据类型

Java数据类型

包装类

Java API

基本数据类型和包装类的转换

  1. 自动装箱

    int t1 = 2;
    Integer t2 = t1;
    
  2. 手动装箱

    Integer t3 = new Integer(t1);
    
  3. 自动拆箱

    int t4 = t2;
    
  4. 手动拆箱

    int t5 = t2.intValue();
    

基本数据类型和字符串的转换

  1. Integer.toString() 基本数据类型转字符串

    int t1 = 2;
    String t2 = Integer.toString(t1);
    
  2. Integer.parseInt() 字符串转基本数据类型

    String t2 = "2";
    int t3 = Integer.parseInt(t2);
    
  3. Integer.valueOf() 先将String对象转换成integer对象,Integer对象自动转换成int

    String t2 = "2";
    int t4 = Integer.valueOf(t2);
    

基本数字类型的初始值

数据类型默认值
byte0
short0
int0
long0L
double0.0d
char‘\u0000’
booleanfalse

几个知识点

  1. 当-128<数字<127 Integer t= 100;虚拟机会从缓存区取对象,若没有对象则会产生一个对象。
Integer t1 = 100;
Integer t2 = 100;
System.out.println(t1==t2);
/*true*/
  1. 8种基本数据类型对应的包装类,除了float和double其他都可以应用对象常量池概念。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值