java wrapper class
1. Make the object class accessible to the world, including simple type attributes and values:
Object o=12; // error
Object o=new Integer(12);
class Integer{
int value;
public Integer(int value){
this.value=value;
}
}
8 wrapper classes: int ===" Integer
char ===》 Character
The other six are all capitalized
double ===》 Double
。。。。
All eight are in the lang package
2. Function: Provide object form for 8 simple types, let Object unify all data;
For properties of numeric type, distinguish between 0 and null;
3, the conversion between the simple type string of the wrapper class
1)int <----> Integer
int i==12;
Integer ii=new Integer(i);
int i2=ii.intValue();
2) int <------> String
String s=i+" ";
int i3=Integer.parseInt(s); // call static method with obvious class name
3) Integer <-------> String
String s2=ii.toString();
Integer ii2=Integer.valueOf(s2);
3, jdk 5.0 automatic sealing
Conversion between simple types and wrapper classes is done automatically by the compiler.