When you use == with a primitive (int, double, char, ...), you are checking whether the values are identical.
When you use == with an object, you are checking whether the 2 objects are stored at the same address, in other words whether the two references are both pointing to the same object.
.equals() changes. Unless it is overridden by the object class, it is the same as ==. Some classes (like
String) have overridden this method so that the class to create objects, they can check whether the contents are equivalent.it will check the <u>contents</u> of the object at the two addresses instead of just the addresses themselves. If you write a class, you may want to override the equals() method in your class so that when people use
Marilyn
This was told by merlin ...
I have one doubt
[code]
public class EQUALSeqeq{
public static void main(String args[])
{
String s1=new String("5");
Long l1=new Long("5");
System.out.println(s1.equals(l1));//displays false
}
}
Here the content is 5 and both String class and Long class overrides equals method so when i use equlas() method they need to check the content
the content here is "5" so it needs to display true
but it is displaying false
can any one explain me about this?