
public final class Integerextends Numberimplements Comparable<Integer>
Integer
类在对象中包装了一个基本类型 int
的值。Integer
类型的对象包含一个 int
类型的字段。
此外,该类提供了多个方法,能在 int
类型和 String
类型之间互相转换,还提供了处理 int
类型时非常有用的其他一些常量和方法
方法:
public class IngegerorInt { public static void main(String[] args) {
// TODO Auto-generated method stub System.out.println(Integer.MIN_VALUE); //-2147483648
System.out.println(Integer.MAX_VALUE); //
System.out.println(Integer.SIZE); //
System.out.println(Integer.BYTES); //
System.out.println(Integer.TYPE); //int int a1=2147483647; //不在在规定范围内,报错:The literal xxx of type int is out of range
Integer b1=new Integer(2147483647);
Integer b2=new Integer(2147483647);
Integer c1=2147483647;
Integer c2=2147483647;
System.out.println(a1==b1); //true MIN_VALUE-MAX_VALUE范围内为true
System.out.println(a1==c1); //true
System.out.println(b1==c1); //false
System.out.println(b1==b2); //false
System.out.println(c1==c2); //false
System.out.println();
System.out.println(b1.equals(a1)); //true 不能 int.equals(Integer)这样比较
System.out.println(b1.equals(c1)); //true
System.out.println(c1.equals(b1)); //true
System.out.println(c1.equals(a1)); //true
System.out.println();
System.out.println(b1.equals(b1)); //true
System.out.println(b1.equals(b2)); //true
System.out.println(c1.equals(c1)); //true
System.out.println(c1.equals(c2)); //true
} }