3.6 Java Basics Summary ① wrapper class, basic data type, string conversion between

Source: Internet
Author: User

Wrapper class, basic data type, string conversion between each other

Each base data type has a corresponding wrapper type

wrapper classes, basic data types, and string conversions between the three are important when converting between them;

One, String to other

string→ Package Type
1, Integer (String str)
Call the wrapper class with a string parameter construct

string→ Basic data types
☆string→int calling the parseint method of the wrapper class

Second, packaging class to other

→string
Call the ToString method of the wrapper class object

→ Basic types
① calling the Xxxvalue method of the wrapper class
Methods of wrapping classes, related to objects, non-static, without reference

After ②jdk1.5, direct assignment
int i = Integer
Since unpacking

III. basic data types transfer to other

→string
①5 + ""
②str = integer.tostring (i);
Using the parameter tostring method of the wrapper class

→ Packaging
① calling the construct of the wrapper class new
After ②jdk1.5, direct assignment =
Automatic Seal box

Object obj = 10;
This is also an automatic enclosure, which refers to the parent class's reference to the Child class object

1Package com.string;2 /**3 * date:2016-3-3-pm 2:56:184 * Class_name:IntegerTest.java5 * Package_name:com.lovo.integer6 * Author:zhangyue7 * Description:8  */9  Public classIntegertest {Ten  One     /** A * @param args -      */ -      Public Static voidMain (string[] args) { the         //TODO auto-generated Method Stub -         //Basic Transfer Packaging - //int i0 = ten; - //integer in0 = new Integer (i0);//The first way: Call the wrapper class with the constructor of the basic type parameter to construct + //Integer in00 = i0;//the second way: After JDK1.5, the automatic sealing box - //Object obj = i0;//This is also the case, and then let the parent class refer to the Child class object + //System.out.println (in0); A          at         //Packaging to Basic - //integer in = new integer (+); - //int i = In.intvalue ();//The first way: Call the wrapper class object's ***value () - //int i0 = in;//second way: After JDK1.5, automatic unpacking - //System.out.println (i); -          in          -         //Wrap to String to //integer in = new Integer (123); + //String str = in.tostring ();//call ToString () of the wrapper class object - //System.out.println (str); the          *         //string to wrap $ //String str = "321";Panax Notoginseng //integer in = new Integer (str);//constructor for calling wrapper class with string argument - //System.out.println (in); the          +          A         //Basic Turn String the //int i = 9527; + //String str = integer.tostring (i);//The first way: Use the wrapper class with the parameter ToString () - //String str0 = i + "";//the second shameless way $ //System.out.println (str); $          -         //The most important--string turn to basic -String str ="54188"; the         inti = Integer.parseint (str);//call the wrapper class's parse*** () -System. out. println (i);Wuyi     } the  -}
integertest

3.6 Java Basics Summary ① wrapper class, basic data type, string conversion between

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.