对应的包装类(位于java.lang包中) | |
---|---|
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
char | Character |
boolean |
-
装箱:从基本类型转换为对应的包装类对象。
如:基本数值---->包装对象
Integer int1 = new Integer(4);//使用构造函数函数
Integer int2 = Integer.valueOf(4);//使用包装类中的valueOf方法
-
拆箱:从包装类对象转换为对应的基本类型。
如:包装对象---->基本数值
int num = int1.intValue();
Integer i = 4; //自动装箱。相当于Integer i = Integer.valueOf(4); i = i + 5; //等号右边:将i对象转成基本数值(自动拆箱) i.intValue() + 5; //加法运算完成后,再次装箱,把基本数值转成对象。
-
-
public static short parseShort(String s)
:将字符串参数转换为对应的short基本类型。 -
public static int parseInt(String s)
:将字符串参数转换为对应的int基本类型。 -
public static long parseLong(String s)
:将字符串参数转换为对应的long基本类型。 -
public static float parseFloat(String s)
:将字符串参数转换为对应的float基本类型。 -
public static double parseDouble(String s)
:将字符串参数转换为对应的double基本类型。 -
public static boolean parseBoolean(String s)