Java-----Basic Data type wrapper class

Source: Internet
Author: User

Objective: In order to conveniently manipulate the basic data type value, encapsulate it as an object, define the property and behavior in the object, enrich the operation of data modification, and the class used to describe the object becomes the basic data type Object wrapper class.

For example: The value range of type int: Integer------>integer.max_value

8 Types of data wrapper classes:

Byte--byteshort--shortint--integerlong-----longfloat-----floatdouble----Double Char----Characterboolean---Boolean the wrapper object is primarily used for three ways of converting between basic data types and strings, basic data type, and string: (1) Basic data Type value + "" (2) static method using Interger: Static string toString (base data Type value) (3) statically string valueOf using the String class (base data type value) string--basic data type(1) Use static method in wrapper class XXX parsexxx (XXX type string) int parseint (int type string);  Long Parselong (long string);  Boolean Parseboolean (Boolean string); for example: if (Boolean.parseboolean ("true")); Tip: Only character has no parse method.      (2) If the string is encapsulated by an integer object, you can use another non-static method, Intvalue (), to convert an integer object to the base data type value integer i=new integer ("123"); Sysout ("I.intvalue"); Conversion Issues:(1) Decimal conversion to other binary binary: static String tobinarystring (int);
16 binary: Static String tohexstring (int);
Octal: Static String tooctalstring (int);
(2) Other conversions: Integer.tostring (N,M) n is the number, M is the number of binary, can be (tobinarystring) 2->2, (tohexstring) 16->16 into the system, (tooctalstring) 8->8, Integer.parseint ("a", b) converts the value A to decimal, where B can be binary, can be octal, can be 16 binary, as long as write B corresponds to the corresponding number (2,8,16) Packing and unpacking:The integer i= new Integer (4), the i=4;->1.5 after the integer, the automatic boxing, and the upper equivalent i=i+6;-> automatic unpacking, equivalent to I=new Integer (I.intvalue () +6); New features for boxing and unpacking 1.5
Integer a =new integer (127=new integer (127); a==b;  // falsea.equals (b);  // true integer x=127; integer y=127; x==y;  // true // ture

Integer a =new integer (+), integer b =new integer (+); a==b;  //// trueinteger x=128; integer y=128//false//ture    

Cause: After the jdk1.5 is boxed automatically, if the boxed is a byte, then the data will not be shared back to re-open space.

Java-----Basic Data type wrapper class

Related Article

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.