Basic data types for learning notes-conversion between wrapper class-string

Source: Internet
Author: User

Basic type wrapper class String class

Int->integer:integer Constructors

Integer-> Int:Integer.intValue () method

INT---String:Integer.toString method, String.valueof () method

String--Int:Integer.parseInt () method

Integer--String:Integer.toString () method, String.valueof () method

Constructor, Integer.valueof () method, String--Integer:integer

Auto-Unboxing after 5.0

For example:

Integer iobj1 = 10; Mount

int j = iobj1; Split

 Public classTestdemo { Public Static voidIntdemo () {//int->string//String-int        intA = 3;        System.out.println (a); String A1=integer.tostring (a);        SYSTEM.OUT.PRINTLN (A1); intA2 =Integer.parseint (A1); SYSTEM.OUT.PRINTLN (A2+ R); //int, Integer//Integer-intInteger A3 =A; inta4 =A3.intvalue ();        SYSTEM.OUT.PRINTLN (A3);        System.out.println (A4); //String, Integer//String-IntegerInteger i =NewInteger (10); String A5=i.tostring ();        System.out.println (A5); Integer I2=Integer.valueof (A5); Integer i3=Integer.parseint (A5); System.out.println (I2+ 5); SYSTEM.OUT.PRINTLN (i3+ 7); }         Public Static voidFloatdemo () {//float->float//float->float        floatF1 = 1.20f; Float F2=F1; floatF3 =F2; SYSTEM.OUT.PRINTLN (F2+ "\ T" +F3); //String, float//float, String        floatF4 = 2.234f; String f5=float.tostring (F4); System.out.println (F5+ 7); F4=float.parsefloat (F5);                SYSTEM.OUT.PRINTLN (F4); //String, Float//Float, StringFloat F6 =NewFloat (12.4); String F7=float.tostring (f6); System.out.println (F7+ 9); F6=float.parsefloat (F7); System.out.println (f6+ 1.1f); }         Public Static voidChardemo () {//Char-Character//Character-Char        Charch = ' P '; Character CH2=NewCharacter (' Q ')); CH2=ch;        System.out.println (CH2); CH=NewCharacter (' u ');                SYSTEM.OUT.PRINTLN (CH); //Char-String//String-Char        CharCH3 = ' Q '; String CH4=character.tostring (CH3);        SYSTEM.OUT.PRINTLN (CH4); CharCH5 = Ch4.charat (0);                System.out.println (CH5); //Character, String//String --CharacterCharacter Ch6 =NewCharacter (' a '); String Ch7= Ch6 + "";        System.out.println (CH7); Character Ch8=character.valueof (CH6);    System.out.println (CH8); }         Public Static voidMain (string[] args) {Testdemo.intdemo (); }}

Basic data types for learning notes-conversion between wrapper class-string

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: 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.