You are trying to compare two different objects, not their values. z and h point to two different Integer objects that have the same value.
z == h
Checks if two objects are equal. Therefore, he will return the lie.
If you want to compare the values stored by the Integer object, use the method equals.
Integer z = new Integer(43); // Object1 is created with value as 43.
z++; // Now object1 holds 44.
Integer h = new Integer(44); // Object2 is created with value as 44.
So, at the end, we have two different Integer objects, i.e. object1 and object2 with a value of 44. Now
z = h
, , z h, . .. object1 == object2
.
Integer z = new Integer(43); // Object1 is created with value as 43.
z++; // Now object1 holds 44. Z pointing to Object1
Integer h = z; // Now h is pointing to same object as z.
z == h
true.
http://www.programmerinterview.com/index.php/java-questions/java-whats-the-difference-between-equals-and/