• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

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

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

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

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

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

Can anybody plz reply .................
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

Sandeep Kumar M
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.