Thanks in advance... Please explain why following happens :
Integer i1 = 6;
Integer i2 = 6;
(i1 == i2)
will return true.
while
Double d1 = 6.5;
Double d2 = 6.5;
(d1 == d2)
will return false.
Why is that? There will be only one object created in both the cases still they behave differently. Using equals method would be better but I was surprised by this behaviour and just wanted to know.