Why == for Integer.valueOf (500) returns false but true for 5?
System.out.println(Integer.valueOf(5) == Integer.valueOf(5));
System.out.println(Integer.valueOf(500) == Integer.valueOf(500));
Output signal
true
false
Why does the first line return true and the second line return false? What a trick here, since both calls are valueOf()
in class Integer
.
+3
source to share