Basic Data Type object Packaging

Source: Internet
Author: User

Basic Data Type object packaging class:Is to encapsulate basic data types into objects according to the object-oriented idea.

Benefits:

1: Basic data can be operated through attributes and behaviors of objects.

2: converts the basic data types and strings.

 

Class name corresponding to the keyword

Byte byte

Short short pasershort (numstring );

IntIntegerStatic Method: parseint (numstring)

Long long

Float float

Double double

CharCharacter

Boolean

 

Basic Data Type object packaging class:All haveXxx parsexxxMethod

Only one type does not existParseMethod: character;

--------------------------------------------------------

Integer object: ★★★☆

To convert a numeric string to a basic data type:

1: encapsulate the string into an integer object and call the method intvalue () of the object ();

2: UseInteger. parseint (numstring)->Class. Method Name: You do not need to create an object and call the class name directly;

 

Convert the basic type to a string:

1: static method in integer string tostring (INT );

2: int + "";

 

Convert a decimal integer to another hexadecimal format:

Convert to binary: tobinarystring

To octal: tooctalstring

Convert to hexadecimal: tohexstring

Tostring (INT num, int Radix );

 

Convert other hexadecimal values to decimal values:

Parseint (string, Radix ); // Convert a given number to a specified base number;

 

After jdk1.5, the basic data type object packaging class is upgraded. During the upgrade, the basic data type object packaging class can be used for calculation like the basic data type.

Integer I = new INTEGER (4 );// Statement written before version 1.5;

Integer I = 4;// Automatic packing, written after version 1.5;

I = I + 5;

// I objects cannot be directly added to 5. In fact, the underlying layer first converts I to the int type and adds it to 5. The Int type conversion operation is implicit.Automatic unpacking: the principle of unpacking is I. intvalue ();I + 5 is an int integer. How do I assign a value to the reference type I? In fact, the results are boxed.

Integer c = 127;

Integer d = 127;

System. Out. println (C = D); // true

//When packing, if the value is within the byte range, the value is the same and no new object is generated. That is to say, the reference with the same value points to the same object.

Basic Data Type object Packaging

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.