So far as I've learnt, == is used to check the memory address difference while equals() is used to check the object content. So, I don't understand why the result would print != as both object contents are 100. Also, I would like to know is the wrapper : Interger x = new Interger(100) immutable? Thanks for help. Andrew [ January 08, 2002: Message edited by: Cindy Glass ]
Yes, Integer objects are immutable. Since you haven't overridden equals() from java.lang.Object, you get the default implementation, which means you get this behaviour (quoted from the API):
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).
This is why == and .equals() are (currently) the same. You need to add an equals method specific to this object...
Oh, I almost forgot. Usually I make a reference to Effective Java by Joshua Bloch (link to the Javaranch Bunkhouse). I find it an invaluable book to keep nearby but it also has great coverage of the whole .equals() thing. (this is what I was refering to when I said "or similar, this is just an example"). To see how great it is, follow the link and read Peter Tran's review (then buy the book! ) Dave. [ January 03, 2002: Message edited by: David O'Meara ]