JAVA base--api (Basic data type Object wrapper class) __java

Source: Internet
Author: User
-Basic data type Object wrapper class.

Byte Byte
Short Short
Int Integer
Long Long
Boolean Boolean
Double Double
Float Float
Char Character

The most common role of the basic data type Object wrapper class,

is for the conversion between the base data type and the string type.


The base data type is converted to a string.

Method One: Basic data type + ""

Method Two: Basic data type. toString (basic data type value);

such as: Integer.tostring (34);//Turn 34 integers to "34";

The string is converted to the base data type.

Method One: Static method parsexxx
xxx a = xxx.parsexxx (String);

int a = Integer.parseint ("123");

Double b = double.parsedouble ("12.23");

Boolean B = Boolean.parseboolean ("true");

Method Two: Non-static method: Xxxvalue
Integer i = new Integer ("123");
int num = I.intvalue ();


Conversion between Systems


Decimal is converted into other systems.
Tobinarystring ();
Tohexstring ();
Tooctalstring ();


The other system is turned into decimal.
parseint (String,radix);

such as: Integer.parseint ("110", 2); 2-in-110 turn into decimal

Integer.parseint ("110", 10); 10 in 110 to decimal (unchanged)



JDK1.5 new feature in this regard		
		//integer x = new Integer (4);

		Integer x = 4;//Auto Boxing. Equivalent to the last sentence

		x = x + 2;//x+2:x for automatic unboxing. into the int type. and 2 for addition operations.
					//And then boxing to X.

		
		//I don't quite meet, the interview may be asked
		Integer m = 128;
		Integer n = 128;

		SOP ("M==n:" + (M==n));	False

		Integer a = 127;
		Integer B = 127;

		SOP ("A==b:" + (A==B));//The result is true. Because A and B point to the same integer object.
						//Because when the value is in byte range, for the new attribute, if the value already exists, it will not open up new space.





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.