Hi Ranchers,
Consider the example shown below:-
class AutoBoxing {
public static void main(
String [] args) {
Integer i1 = 1000;
Integer i2 = 1000;
if(i1 != i2) {
System.out.println("Different Objects");
}
if(i1.equals(i2)) {
System.out.println("Meaningfully equal");
}
Integer i11 = 10;
Integer i12 = 10;
if(i11 == i12) {
System.out.println("Same Objects");
}
if(i11.equals(i12)) {
System.out.println("Meaningfully equal");
}
}
}
output:-
Different Objects
Meaningfully equal
Same Objects
Meaningfully equal
Why if(i1 != i2) is true in first case(value 1000 for i1 and i2) and if(i11 == i12) is true in the second (value 10 for i11 and i12) . could anyone explain me?
Thanks in advance.