Reprinted from Http://zhidao.baidu.com/question/2052192149152534987.html
First, the conversion between the basic data types is not all convertible, and you cast problems, such as the conversion of string type int type, then the JDK for the convenience of users to provide the appropriate wrapper class.
Example:
public class integer{
private int i;
Public Integer (int a) {
I =a;
}
public static int Parsetoint () {
return i;
}
public static Integer valueOf (String str) {
Encapsulates a series of logic that eventually converts STR to an int type of INTEGERSTR
return new Integer (INTEGERSTR);
}
}
Above is an example of a JDK for integers such as Integer INTG = integer.valueof (str); int i = Intg.parsetoint ();
This makes it easy for the user to complete the conversion of the string and int so that the user
Second, sometimes a function needs to pass a variable of object and you want to pass int type to go in obviously not, how to do it, use the wrapper class.
public void Test (Object obj) {
}
You want to pass 5 in, you can do that.
Test (new Integer (5));
In summary, there are three uses of the packaging class
A transformation between the implementation base types
The second is to facilitate the function transfer value
Third, in some places to use the object when it is convenient to replace the basic data type
The role of the Java wrapper class