The object cannot be forcibly converted to integer.
The object can be forcibly converted to a string.
Integer A = integer. parseint (string Str)
Packing and unpacking? Is the unpacking automatic?
The eight basic types are not corresponding to the system. You cannot call methods such as tostring (), hashcode (), getclass (), and equals () as objects.
For the eight basic types, qigong provides packaging for each basic type.
Int ---- integer
Char --- character
Float ---- float
Double --- double
Byte ---- byte
Short ---- short
Long --- long
Boolean --- Boolean
Box is the basic type corresponding to them, so that they have the characteristics of objects.
In the opposite direction of the Unbox, the object of the reference type is simplified to the value type.
Before jdk1.5, You need to manually box and Unbox
Jdk1.5 is automatically completed.
In the wrapper packaging class, there is an important static method parse. You can convert the string type to the corresponding basic data type. If the value in the string cannot be converted to the basic data type, Java is thrown. lang. numberformatexception
Public class parseint {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Int p = 1;
Integer q = new INTEGER (p); // manually boxed
Int M = Q. intvalue (); // manually unpack
System. Out. println ("manual box q =" + q );
System. Out. println ("manual Unbox M =" + M );
Int J = 2;
Integer A = J;
Int B =;
System. Out. println ("auto Box A =" + );
System. Out. println ("auto Unbox B =" + B );
String STR = new string ("30i ");
Try
{
Int pp = integer. parseint (STR );
System. Out. println (PP );
}
Catch (exception E)
{
E. printstacktrace ();
}
}
}