It’s a rule that == is used to compare references, not values. To compare values for equality equals() method should be used.
However, as of Java 5, you can also use == to check if two objects’ values are the same… But it works only for the following wrapper objects, if their primitive counterparts’ values are the same:
- Boolean
- Byte
- Character for values: \u0000 (0) ÷ \u007f (127)
- Byte and Integer for values: -128 ÷ 127


Nice post Jarosław. Also look at this for equals and hashCode
http://blog.vaibought.com/2010/05/chemistory-of-equalsto-and-hashcode-in.html
it does not “work only” for the wrapper objects given above.
It also works for Long, normally in the range -128 to 127.
It also works for interned String (see String.intern()).
The the upper limit of the (cached) Integer range can be changed (property java.lang.Integer.IntegerCache.high).
Also it should be noted that this is highly implementation dependent!