Possible Duplicate:
Why Java does not see that Integers are equal?
I have 2 integers that I assign from the same argument.
One of the integers I decrease the value by 1 then increment the value by 1.
When I compare them again they are not always equal.
This is from my book, can someone please explain, I cannot understand my books explanation.
class Test{
public static void main(String[] args){
Integer i = Integer.parseInt(args[0]);
Integer j = i;
System.out.println("1:" + i + ", j:" + j);
i--;
System.out.println("2:" + i + ", j:" + j);
i++;
System.out.println("3:" + i + ", j:" + j);
System.out.println((i==j));
}
}
Output: Input 256 as argument
1:256, j:256
2:255, j:256
3:256, j:256
false
Thank you for your consideration.