Wrapper class Integer

/ ** 
 * packaging 
 * packaging in order to solve the basic types can not be directly involved oriented 
 * developed object in question. 
 * 8 correspond to eight different basic types of packaging, which represents 6 
 * digital wrapper class inherits from java .lang.Number, the other two 
 * a Inherited from Object 
 * @author TA 
 * 
 * / 
public  class IntegerDemo1 {
     public  static  void main (String [] args) {
         int D = 128 ;
 //         Integer I1 = new new Integer (D);
 //         Integer i2 = new new Integer (d); 
        / * 
         * the Java static methods we recommend the use of packaging like: 
         * valueOf to the basic type into a wrapper class 
         * / 
        Integer I1 =  Integer.valueOf (d);
        Integer i2 = Integer.valueOf(d);
        
        System.out.println(i1==i2);//false
        System.out.println(i1.equals(i2));//true
        
        
        //包装类转换为基本类型
        int i = i1.intValue();
        System.out.println(i);
        
        double dou = i1.doubleValue();
        System.out.println(dou);
        
        long lon = i1.longValue();
        System.out.println(lon);
        
        byte b = i1.byteValue();
        System.out.println(b);
    }
}
/ ** 
 * numeric wrapper class has two constants: 
 * MAX_VALUE, MIN_VALUE were recorded substantially corresponding 
 * type range 
 * @author TA 
 * 
 * / 
public  class IntegerDemo2 {
     public  static  void main (String [] args) {
         int IMAX = Integer.MAX_VALUE; 
        System.out.println (IMAX); 
        int Imin = of Integer.MIN_VALUE; 
        System.out.println (Imin); 
        
        Long Lmax = of Long.MAX_VALUE; 
        System.out.println (Lmax) ; 
        Long Lmin = of Long.MIN_VALUE; 
        System.out.println (Lmin); 
        
        / *
         * Providing a packaging function, static method: parseXXX 
         * This method may parse the string to the corresponding base type 
         * data, provided that the string is converted correctly to describe 
         the basic types can be stored value *. 
         * / 
        String STR = "123" ;
         int A = the Integer.parseInt (STR);
         Double Dou = Double.parseDouble (STR); 
        System.out.println (A); // 123 
        System.out.println (Dou); // 123.123 
    } 
}
/ ** 
 * After JDK5 launched a new feature: automatic entry boxes 
 . * This feature is recognized by the compiler, rather than a virtual machine 
 * compiler see each other basic assignment types and wrapper class 
 * When will add an additional switch to convert them. 
 * @author TA 
 * 
 * / 
public  class IntegerDemo3 {
     public  static  void main (String [] args) {
         / * 
         * here triggered automatically unpacking characteristics compiler 
         * compiler code is changed : 
         * = I int new new Integer (. 1) .intValue (); 
         * / 
        int I = new new Integer (. 1 );
         / * 
         * trigger automatic packing characteristics, the code will be changed to: 
         * Integer in Integer.valueOf = (I ); 
         * / 
        Integer in = i;
    }
    
}

Guess you like

Origin www.cnblogs.com/hello4world/p/12105223.html