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