What is the differences between == operator and equals() method?
• No equals() method for primitive types. Of course, primitive type wrapper classes (e.g. Integer class) do. • == operator compares the values of primitive types. • == operator compares the reference (values) of Objects. • Unlike C++, Java does not allow operator overwriting. Which means two identical objects A and B, A==B will never happen. • Object.equals() will behave exact the same as ==, unless it is overridden by the subclass. • More equals / == examples here, TestEqual.java • Warning: Don’t try this at work!