I have been playing with == in wrapper classes. There's some weird thing that I encountered.
Integer i1 = 3;
Integer i2 = 3;
if(i1 != i2)
{
System.out.println("i1 and i2 are not equal"); // if condition returns false in this case
}
which is working perfectly fine as far as my knowledge is concerned.
whereas, If I instantiate wrapper with
Integer i1 = 1000;
Integer i2 = 1000;
if(i1 != i2)
{
System.out.println("i1 and i2 are not equal"); // if condition returns true in here
}
Then I am getting confused with the dual behavior of JVM with respect to the different values assigned to wrapper. Why is this happening so? Please share your thought on this.
Thanks