BTW you can shorten your code to
System.out.println("Integer 127 == " + ((Integer) 127 == (Integer) 127));
System.out.println("Integer 128 == " + ((Integer) 128 == (Integer) 128));
for(int i=0;i<5;i++) {
System.out.println(
"Integer 127 system hash code " + System.identityHashCode((Integer) 127)
+ ", Integer 128 system hash code "+System.identityHashCode((Integer) 128));
}
prints
Integer 127 == true
Integer 128 == false
Integer 127 system hash code 1787303145, Integer 128 system hash code 202703779
Integer 127 system hash code 1787303145, Integer 128 system hash code 1584673689
Integer 127 system hash code 1787303145, Integer 128 system hash code 518500929
Integer 127 system hash code 1787303145, Integer 128 system hash code 753416466
Integer 127 system hash code 1787303145, Integer 128 system hash code 1106961350
You can see that 127 is the same object each time, whereas the object for 128 is different.