equals(): ========= package io.ashokit.pack1; import java.util.Objects; class A{ String s1; A(String s1){ this.s1 = s1; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; A other = (A) obj; return Objects.equals(s1, other.s1); } } public class MainClass { public static void main(String[] args) { A a1 = new A("Java"); A a2 = new A("Java"); System.out.println(a1 == a2); System.out.println(a1.equals(a2)); System.out.println("=================="); String s1 = new String("Java"); String s2 = new String("Java"); System.out.println(s2 == s1); System.out.println(s1.equals(s2)); System.out.println("=================="); } } ========================== -> in general, the equal operator (==) can compare the object's addresses are same or not. if addresses are same ==> == return: true otherwise: == return: false -> equals() can compare the internal content of objects: if internal content of both objects are same : equals() can return: true otherwise: false -> equals() can be overridden in the strings already. -> when we can apply equals() on two object of class A (user-defined), in this case, equals() can behave like equal operator. because equals() method was not overridden. -> if we can override the equals() in class A: then it will compare with the internal content of two objects of class A. -> equals() is Object class method.