package integer;

public class IntegerTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Integer a1 = 127, a2 = 127, b1 = 128, b2 = 128;
		System.out.println(a1==a2);
		System.out.println(a1.equals(a2));
		System.out.println(b1==b2);
		System.out.println(b1.equals(b2));
	}

}



true


true


false


true

引用回答

JVM会自动维护八种基本类型的常量池,int常量池中初始化-128~127的范围,所以当为Integer i=127时,在自动装箱过程中是取自常量池中的数值,而当Integer i=128时,128不在常量池范围内,所以在自动装箱过程中需new 128,所以地址不一样。