java中一切皆对象,所以对基本数据类型进行了包装。
public class IntegerDemo01{ public static void main(String args[]){ int i = 10 ; Integer i2 = new Integer(i) ; // 装箱操作 int j = i2.intValue() ; // 拆箱操作 System.out.println(j * j) ; } };
jdk1.5以后,就可以进行自动拆箱和装箱。
public class IntegerDemo02{ public static void main(String args[]){ int i = 10 ; Integer i2 = i ; // 自动装箱操作 int j = i2 ; // 自动拆箱操作 System.out.println(j * j) ; } };
public class IntegerDemo03{ public static void main(String args[]){ System.out.println(Integer.MAX_VALUE) ; System.out.println(Integer.MIN_VALUE) ; } };
public class IntegerDemo04{ public static void main(String args[]){ String str = "12sss3" ; // 字符串由数字组成 int i = Integer.parseInt(str) ; // 将字符串变为int型 System.out.println(i++) ; } };