First, that the basic data types in total following eight
integer byte short int long
float float double
character char
Boolean boolean
The origin of the wrapper class : Although the basic data type is easy to use, but there is no corresponding method of operation of these basic types of data, so we can use a class of the basic types of data are encapsulated, defined methods in the class, this our class is the wrapper class.
The corresponding relationship
byte -> Byte
Short -> Short
int -> Integer
Long -> Long
float -> Float
Double -> Double
char -> Character
boolean -> Boolean
We are talking packing is the basic data types into a packaging
and unpacking we call is to convert basic data packaging type
to type Integer Example
1 Packing
1.1 constructor
1.1.1 using Integer (int value ) construction method, is converted to an int type Integer
Integer Integer integer01 new new = (. 1);
1.1.2 using Integer (String s) constructor, the type String to convert Integer.
Note that the string must be a basic type of string. For example, "123", otherwise an exception is thrown, for example, "AB2"
Integer = integer02 new new Integer ( "123");
1.2 Static method
1.2.1 static Integer valueOf (int i) , the value of int Returns the specified instance Integer
Integer integer03 Integer.valueOf = (. 1);
1.2.2 static Integer valueOf (String S), returns the value of the specified String Integer examples
Integer integer04 = Integer.valueOf ( "123" );
1.3 automatic packing
int. 1 I01 =
Integer I05 = I01;
2 unboxing
2.1 Method members
int intValue () returns an int Integer value of the
int i02 = integer05.intValue ();
2.2 automatic unpacking
int i03 = integer05;
---------- ----------- gorgeous dividing line
the basic string data type conversion type
1 basic data types -> String
1.1 + basic data types " "; // empty string
int. 5 = I04;
string string01 + I04 =" ";
1.2 Static corresponding method of packaging toString (parameter)
String string02 = Integer.toString (100);
Static method valueOf (parameter) 1.3 String Class
static String valueOf (int i): Returns the string representation of the int type
String string03 = String.valurOf (100);
2 string -> basic data types
2.1 static method of packaging a corresponding
static int paseInt (S String):
int = the Integer.parseInt I05 (string03);
System.out.println (i05-10); // 90