厦门酒店网站建设,扬州有做义工的地方或网站嘛,丝印网版制作,泉州做网站的自动装箱过程是通过调用包装类的valueOf#xff08;#xff09;方法实现的#xff0c;二自动拆箱过程是通过调用包装类的xxxValue#xff08;#xff09;方法实现的#xff08;xxx代表对应的基本数据类型#xff0c;如intValue#xff0c;doubleValue等#xff09;。 …自动装箱过程是通过调用包装类的valueOf方法实现的二自动拆箱过程是通过调用包装类的xxxValue方法实现的xxx代表对应的基本数据类型如intValuedoubleValue等。
package demo06;public class TestWrapper2 {public static void main(String[] args) {//1.自动装箱和自动拆箱Integer in 5;Integer in2 new Integer(5);//valueOf()int i in2;int i2 in2.intValue();//2. equalsInteger in3 new Integer(56);Integer in4 new Integer(56);System.out.println(in3in4);//falseSystem.out.println(in3.equals(in4));//trueInteger in5 25;Integer in6 25;System.out.println(in5in6);//trueSystem.out.println(in5.equals(in6));//trueInteger in7 256;Integer in8 256;System.out.println(in7in8);//falseSystem.out.println(in7.equals(in8));//true}
}Integer类提供了一个静态内部类IntegerCache对于定义一个静态数组cache长度为256赋值为-128到127。对于自动装箱时如果是-128到127范围内的数据
直接获取数组的指定值对于中国范围之外的数据通过new Integer重新创建对象这么做的目的是提高效率。