I wrote the simple code:
public static void main(String[] args) {
Integer i1 = 127;
Integer i2 = 127;
boolean flag1 = i1 == i2;
System.out.println(flag1);
Integer i3 = 128;
Integer i4 = 128;
boolean flag2 = i3 == i4;
System.out.println(flag2);
}
But, strangely, the result is as below:
true
false
Can you guys please explain why the difference occurs?