Hi,
Check the following program:
public class Temp
{
public static void main(
String[] args)
{
Integer i1 = 1000;
Integer i2 = 1000;
if(i1 != i2) System.out.println("different objects i1 i2");
if(i1.equals(i2)) System.out.println("meaningfully equal i1 i2");
Integer i3 = 10;
Integer i4 = 10;
if(i3 != i4) System.out.println("different objects i3 i4");
if(i3.equals(i4)) System.out.println("meaningfully equal i3 i4");
}
}
The output is:
different objects i1 i2
meaningfully equal i1 i2
meaningfully equal i3 i4
Please clarify.Why i1 and i2 are different objects when both are Integer and have value 1000 which is in the range of int.
Thanks