Basic data type Object wrapper class
encapsulates a base data type into an object's The advantage is that you can Packing class to manipulate the data by defining more functional methods in the .
One of the most common operations: for converting between basic data types and strings.
Basic data type Object wrapper class new features
JDK1.5 simplifies the way you define it.
Integer x = new Integer (4); can be written directly
Integer x = 4;// Auto-boxing.
x = x + 5;// automatic unpacking. Through the intvalue method.
Need to note:
integer x = null; nullpointerexception
@Testpublic void test01 () {/* * basic Data type Object wrapper class. * * bytebyte * shortshort * intinteger * longlong * float Float * doubleDouble * booleanBoolean * charcharacter * * common scenarios for this object: * convert between basic data values and strings. * * base Type Value---> String. 34+ "" = " string.valueof" (Basic data Type value); * static string tostring ( Base type value); * * string---> base type value. static Basic Type parsexxx (String) "123" 123 * static xxx parsexxx (string); * */system.out.println (Integer.parseint ("123") +1);//result is 124//system.out.println ( Integer.parseint ("abc") +1); //numberformatexceptionsystem.out.println (integer.max_value); Integer x = new integer (123); Integer y = new integer ("123"); System.out.println (x==y);//false is a comparison of twoThe address value of the System.out.println object (X.equals (y));//true compares the values of two objects// integer overrides the Equals method of object. Establish your own judgment on the same basis, as long as the values in the object are the same. Binary conversion. Decimal--and other binary. System.out.println (integer.tobinarystring ( -6)),  //2 System.out.println (integer.tohexstring); // 16 binary//Other binary----decimal. System.out.println (Integer.parseint ("110", 2));//Basic data value---> object. Integer i = new integer (+); integer ii = integer.valueof (23);//Object----> The base data type value. Int num = i.intvalue ();}
After @Testpublic void test02 () {/** * JDK1.5, the basic data type Object wrapper class has a new feature. * Automatic packing and unpacking. *///integer i = new Integer (//jdk1.5); Simplified to: Integer i = 34;//integer i = integer.valueof (34); Automatic boxing. i = i + 2;//i+2,i first turns into an integer, I.intvalue () automatically unpacking. i = integer.valueof (I.intvalue () +2); SYSTEM.OUT.PRINTLN (5);//auto-boxed integer x = new Integer (123); Integer y = new integer (123); System.out.println (x==y);//falsesystem.out.println (X.equals (y));//trueinteger a = 127;//if the same value for the Internet In the range of byte, memory is optimized, there is no need to re-open space, the address of the value is used directly. Integer B = 127; System.out.println (a==b);//true System.out.println (a.equals (b));//trueinteger c = 128;integer d = 128; System.out.println (C==d); FalseSystem.out.println (C.equals (d)); True
Base type Object wrapper class