I know that i am comparing reference while i'm using == which is not a good idea but i did not understand why is this happening.
Integer a=100;
Integer b=100;
Integer c=500;
Integer d=500;
System.out.println(a == b); //true
System.out.println(a.equals(b)); //true
System.out.println(c == d); //false
System.out.println(c.equals(d)); //true
The Java Language Specification says that the wrapper objects for at least -128 to 127 are cached and reused by
Integer.valueOf()
, which is implicitly used by the autoboxing.