1.Integer类概述
① 解释:把int封装成对应的类;
②方法:在 int 类型和 String 类型之间转换;
③还提供了处理 int 类型时非常有用的其他一些常量和方法。
2.构造方法
① public Integer(int value)
② public Integer(String s) //数字类字符串输出int
public class Demo2_Integer {
public static void main(String[] args) {
//Integer类提供的静态常量,可通过类名查看。
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
//构造方法:转换成对应的int型
Integer i1=new Integer(100);//字符串"100"也能转换成对应int型
System.out.println(i1);
Integer i2 = new Integer("abc"); //abc不是数字字符串,异常
System.out.println(i2);
}
}
附录:java.lang.NumberFormatException数字格式异常