Integer int1 = 2;
Integer int2 = 2;
System.out.println(int1 == int2); // ok
Run code
/Libray/.../jdk1.8.0_241.jdk/.../..java...
true
Process finished with exit code 0
Compare Double object
Double dou1 = 4.0;
Double dou2 = 4.0;
System.out.println(dou1 == dou2);
Run code
/Libray/.../jdk1.8.0_241.jdk/.../..java...
false
Process finished with exit code 0
I think it's possible to compare integers using autoboxing and unboxing, but why it doesn't work for Double?