0
点赞
收藏
分享

微信扫一扫

【JAVASE基础】自动装箱和拆箱

5.3自动装箱和拆箱
●自动装箱:基本数据类型自动转成引用类型int -> Integer
●自动拆箱:引用类型自动转成基本数据类型Integer ->int

package com.sdjzu.autoBox;

public class AutoBoxTest {
    public static void main(String[] args) {
        auto1();
        auto2();
    }
    public static void auto1(){
        //自动装箱
        Integer integer = 100;
        System.out.println("integer = " + integer);
        //自动拆箱
        System.out.println("(integer+1) = " + (integer + 1));
    }
    public static void auto2(){
        Integer i1=new Integer(123);
        Integer i2=new Integer(123);
        System.out.println("(i1==i2) = " + (i1 == i2));//F
        System.out.println("i1.equals(i2) = " + i1.equals(i2));//T
        System.out.println("********************");
        Integer i3=1280;
        Integer i4=1280;
        System.out.println("(i3==i4) = " + (i3 == i4));//F
        System.out.println("i3.equals(i4) = " + i3.equals(i4));//T
    }
}

在这里插入图片描述

举报

相关推荐

0 条评论