What is the difference between equals() and == ?

#1
according to java.lang.Object class equals() defined as

public boolean equals(Object object) {
return this == object;
}

Ex:
class EqualsNotEqualTo {
public static void main(String args[]) {
String s1 = "Hello";
String s2 = new String(s1);
System.out.println(s1 + " equals " + s2 + " -> " +
s1.equals(s2));
System.out.println(s1 + " == " + s2 + " -> " + (s1 == s2));
}
}

output:
Hello equals Hello -> true
Hello == Hello -> false
how it will differ, (bcoz equlas() internally compares using == operator ) ????????????????????????

Can anybody plz reply .................
 
#2
Re: wt is the difference between equals() and == ?

the equlas(Object o) present in Object class is ment for reference comparasion so the functionality of equals(Object o) present in Object class and == is same.The equals(Object o) present in String class is for content comparasion. the equals(Object o) present inString class is overridden for content comparasion.


hope so u understand this concept

Thanks&Regards
Sandeep Kumar M
 
#4
The point when utilized with objects, those == driver compares the two item references Furthermore determines if they allude of the same example. Equals() is a strategy accessible in the string population that is used to look at two strings What's more figure out if they are rise to.
 
Top