OverviewThe benefit of encapsulating basic data types into objects, based on the idea of everything in Java, is that you can define more functional methods in an object to manipulate the data. The most common function of the basic data type Object wrapper class is to convert between the base data type and the string type.
corresponding RelationshipData type wrapper class byte byte short short int Integer long long boolean float float double double Char Character
Conversion of string to numeric type (for example, int)1. String-> numeric value (only character not resolved) static int parseint (string s) static int parseint (string s, int radix)
2. Numeric-> string static string string.valueof (int i) static string tostring (int i) static string tostring (int i, int rad ix) static string tobinarystring (int i) static string tohexstring (int i) static string tooctalstring (int i)
3. Numeric/String-> wrapper class object Builder: Integer (int/string) static integer valueof (int i) static integer valueof (string s) static inte Ger valueof (String s, int radix)
4. Packing class object-> value/String int intvalue (); String toString ();
Sample
1. String-> numeric value
intNUM1 = Integer.parseint ("100"); 100
intnum2 = Integer.parseint ("100", 16); 256//You can use this method to convert other binary to decimal//Parse Exceptions: NumberFormatException//2. Numeric-> String str1 = integer.tostring (100); "M" String str2 = integer.tostring (100, 4); "1210" String STR3 = integer.tobinarystring (100); "1100100" String STR4 = integer.tooctalstring (100); "144" String STR5 = integer.tohexstring (100); "64"//can convert decimal to other binary String STR6 = string.valueof (100); "100"//3. numeric/String-> wrapper class object Integer inte1 =
NewInteger (100); Integer inte2 = integer.valueof (100); Integer Inte3 =
NewInteger ("100"); The Integer inte4 = integer.valueof ("100"); Integer inte5 = integer.valueof ("100", 4); 16//4. Wrapper class object-> value/String
intNo = Inte1.intvalue (); M-String str = inte1.tostring (); "100"
Automatic Box Unboxing (Java 5 support)Integer i = 10; Automatic boxing, equivalent to: Integer i = integer.valueof (10); i = i + 1; Automatic unpacking, equivalent to: i = integer.valueof (I.intvalue () + 1);
Memory-resident mechanism (mode of privilege)In automatic boxing, if the range of values is in byte range, the shared memory space is similar to a string constant. Integer a1 = 127; Integer A2 = 127; SYSTEM.OUT.PRINTLN (a1 = = A2); True
Integer B1 = 128; Integer b2 = 128; System.out.println (B1 = = b2); False
Case Study
Packagewrapper;
ImportJava.util.Arrays;
Public
classwrappertest {
Private
Static
FinalString space = "";
Public
Static
voidMain (string[] args) {/* To sort data in a string * thought: * 1. Converts a string to an array. * 2. Sorts the array.