Java代码中几种装箱和拆箱的方法(里面添加了其他几种方法)

public class Work1 {
public static void main(String[] args) {
//1.构造方法–装箱
Integer i1 = new Integer(6);
Integer i2 = new Integer(“6”);
Double d1 =new Double(6.1);
Double d2 =new Double(“3.2”);
Boolean b = new Boolean(true);
Boolean b2 = new Boolean(“truE”);
Character c1 = new Character(‘c’);

    //2.实例方法:xxxValue -- 拆箱
    int i = i1.intValue();
    Boolean b3 = b.booleanValue();
    char c2 = c1.charValue();

    //3.静态方法toString -- 基本类型 --> String
    String s = Integer.toString(6);
    String s2 = Double.toString(3.1);

    //4.静态方法parsexxx String --> 基本类型
    int i3 = Integer.parseInt("6");
    Double d3 = Double.parseDouble("6.1");
    Boolean b4 = Boolean.parseBoolean("true");

    //5.静态方法valueOf -- 装箱
    Integer i4 = Integer.valueOf(6);
    Double d4 = Double.valueOf(3.6);

    //6.静态方法:compare 比较,返回int
    int m = Double.compare(3.6,5.6);
    System.out.println(m);

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值