装箱和拆箱IntegerTest

package com.example.demo;

/**
 * @Description 装箱和拆箱
 * @Auther gf.x
 * @Date 2020/1/8 13:44
 */
public class IntegerTest {
    public static void main(String[] args) {
        Integer t = new Integer(1000); //把数字1000包装成一个对象
        System.out.println(Integer.MAX_VALUE); //2147483647
        System.out.println(Integer.MIN_VALUE); //-2147483648
        System.out.println(Integer.toHexString(t)); //3e8 把t转化为16进制输出

        //把字符串转换成10进制的数字(返回值int类型)
        Integer i = Integer.parseInt("123"); 
        System.out.println(i + 20); //143
        //或者这样写
        Integer i2 = new Integer("123"); //构造方法调用了上面的parseInt()方法
        System.out.println(i2.intValue()); //123

        Integer d = 1234;
        Integer d2 = 1234;
        System.out.println(d == d2); //false
        System.out.println(d.equals(d2)); //true 可以看源码知比较的是value值

        Integer d3 = -128;
        Integer d4 = -128;

        //true  [-128, 127]之间的数,(运行阶段)仍当做基本数据类型来处理;
        //为了提高运行效率
        System.out.println(d3 == d4); 
        System.out.println(d3.equals(d4)); //true
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值