The reason that ==returns true for the second case is because the primitive values ββmarked with shells are small enough to be interned to the same value at runtime. Therefore they are equal.
In the first case, the Java integer cache is not large enough to contain the number 1000, so you create two different wrapper objects, comparing that the link returns false.
Integer#valueOf(int) ( IntegerCache.high - 127):
public static Integer valueOf(int i) {
if(i >= -128 && i <= IntegerCache.high)
return IntegerCache.cache[i + 128];
else
return new Integer(i);
}
, .equals(), true, , .