Integer i1 = 256;
Integer i2 = 256;
if (i1 == i2) System.out.println("Equal!");
else System.out.println("Not equal!");
The output in this case would be "Not equal!" as these are two separate Integer objects,
so "==" returns false.
However, the following
Integer i1 =100;
Integer i2 = 100;
if (i1 == i2) System.out.println("Equal!");
else System.out.println("Not equal!");
will return "Equal!", Remember that int values from -127 to 127 are in that
range of immutable wrapper types, so the VM actually uses the same
object instance (and therefore memory address) for both i1 and i2. As a
result, == returns a true result.