I wanted to check Integer equality in my application but came across a strange behavior. At some point my application was working correctly but at some point it was failing. So I just written a test code over here
public class EqualityTest {
public static void main(String args[]) {
Integer a = 100;
Integer b = 100;
Integer c = 1000;
Integer d = 1000;
if (a == b) {
System.out.println("a & b are Equal");
}
else {
System.out.println("a & b are Not Equal");
}
if (c == d) {
System.out.println("c & d are Equal");
} else {
System.out.println("c & d are Not Equal");
}
}
}
Output
a & b are Equal
c & d are Not Equal
here my question is why c and d are not equal?