8. General methods of packing class

Source: Internet
Author: User

/*** Packaging Class common methods **/ Public classDemo { Public Static  voidMain (string[] args) {//Xxxvalue (): wrapper class converted to basic typeInteger integerid=NewInteger (25); intIntid=Integerid.intvalue ();                System.out.println (INTID); Boolean Booleanval=NewBoolean (true); BooleanBool2=Booleanval.booleanvalue ();        System.out.println (bool2); System.out.println ("*************************"); //toString (): Returns the base type data represented by the wrapper object as a stringString sex=character.tostring (' Male '); String ID=integer.tostring (89);        SYSTEM.OUT.PRINTLN (Sex);        SYSTEM.OUT.PRINTLN (ID); String Sex2= ' Male ' + ' "; String Id2=89+ "";        System.out.println (SEX2);        System.out.println (ID2); System.out.println ("*************************"); //all wrapper classes valueof (type value)Integer Intvalue=integer.valueof (21);        System.out.println (Intvalue); Boolean BOOL=boolean.valueof (false);        SYSTEM.OUT.PRINTLN (BOOL); System.out.println ("*************************"); //In addition to the character class, other wrapper class valueof (String s)Intvalue=integer.valueof ("32"); //bool=boolean.valueof ("true");Bool=boolean.valueof ("Love"); //Compile Error//Character c=character.valueof ("a");System.out.println (intvalue);        SYSTEM.OUT.PRINTLN (BOOL); System.out.println ("*************************"); //parsexxx (): Converts a string to the corresponding base data type data (except character)        intI=integer.parseint ("89");        System.out.println (i); //Boolean Flag=boolean.parseboolean ("true"); //boolean Flag=boolean.parseboolean ("TRue"); //boolean Flag=boolean.parseboolean ("Love");        BooleanFlag=boolean.parseboolean ("false");        SYSTEM.OUT.PRINTLN (flag); System.out.println ("*************************"); //automatic conversion of basic types and wrapper classes: Boxing and unpacking//PackingInteger intobject=5; //Unpacking        intIntvalue2=Intobject; System.out.println (Intobject+ "\ T" +intValue2); }}

8. General methods of packing class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.