Java common tools --java packaging

First, basic data types and packaging

Packing: basic data types - packaging

Unpacking: Packaging - basic data types

Package com.imooc.wrap; 

public  class WrapTestOne { 

    public  static  void main (String [] args) {
         // Packing: converting the basic data types into a packaging
         @ 1 autoboxing 
        int T1 = 2 ; 
        Integer T2 = T1;
         // 2. manual packing 
        Integer = T3 new new Integer (T1); 
        
        // test 
        System.out.println ( "int type variable = T1" + T1); 
        System.out.println ( "Ingeter type variable t2 = "+ T2); 
        System.out.println ( " = Ingeter type variable T3 "+ T3); 
        System.out.println ("=======================" );
         // unboxing: converting the base data packaging
         // 1. automatically unpacking, by assignment = achieve 
        int T4 = T2;
         // 2. manually unpacking 
        int T5 = t2.intValue ();
         Double T6 = t2.doubleValue ();
         // test 
        System.out.println ( "Integer Object type = T2" + T2 ); 
        System.out.println ( "automatically after unpacking, int type object = T4" + T4); 
        System.out.println ( "manually after unpacking, int type object = T5" + T5); 
        the System.out. the println ( "manually unpacking, double type object = T6" + T6); 

    } 

}

Second, the basic string data type and

Basic data types - String: packaging .toString (basic data types);

String - basic data types: packaging .parseInt (string); / packaging .valueOf (string);

Package com.imooc.wrap; 

public  class WrapTestTwo { 

    public  static  void main (String [] args) {
         // basic data type into a string 
        int T1 = 2 ; 
        String T2 = Integer.toString (T1);
         // Test 
        System .out.println ( "int type to objects of type String = T2" + T2); 
        System.out.println ( "======================= ===== " );
         // string into basic data types
         // the parse 1. wrapper class 
        int T3 = the Integer.parseInt (T2);
         // 2. valueOf first converted into a string of packaging packaging category, and then complete the basic automatic type conversions unboxing 
        int= T4 Integer.valueOf (T2);
         // Test 
        System.out.println ( "String type to objects of type int = T3" + T3); 
        System.out.println ( "String type to objects of type int t4 =" + T4); 
    } 

}

 

Guess you like

Origin www.cnblogs.com/loveapple/p/11139989.html