Here is my code:
I was checking equals
method and ==
operator.
I know, if we are not using primitive data types, we should prefer equals method. But here it is behaving differently. Aren't d1 and d2 same references.
Integer i1 = 2;
Integer i2 = 2;
System.out.println(i1==i2);
Double d1 = 2.2;
Double d2 = 2.2;
System.out.println(d1==d2);
Output is:
true
false
Why is it false in case of Double? Thank you.