JAVA中Integer的拆箱与装箱

Integer

字符串与数值 的转换

String str="1000";
 int i=1000;
 //int --> String
 //方式一  
 String s1=i+"";//int类型加上一个空字符串 返回就是字符串
 System.out.println(s1);
 //方式二
 String s2=String.valueOf(i); //调用String的方法valueOf, 将int类型变量传进去,返回一个字符串
        
        
 //String --> int
 //方式一 : String -->Integer -->int
 Integer i2=Integer.valueOf(str); //调用Integer的方法valueOf, 将String类型的参数传进去, 得到一个Integer类型
  int x=i2.intValue(); //int intValue() 返回此值Integer为int
       
  //方式二
  int i3 = Integer.parseInt(str); //直接通过Integer的parseInt方法, 返回一个int

总结

  1. int 转换为String --> static String valueOf(int);

返回int参数的字符串, 该方法时String类中的方法

  1. String 转换int -->static int parseInt(String s)

将字符串解析为int类型,该方法是Integer类中的方法

拆箱与装箱

  • 装箱

把基本数据类型转换为对相应的包装类类型

  • 拆箱

把包装类类型转换为对应的基本数据类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值