Both equals() method and the == operator is used to compare two objects in Java. == is an operator and equals() is method. But == operator compares reference or memory location of objects in the heap, whether they point to the same location or not.
Whenever we create an object using the operator new it will create new memory location for that object. So we use == operator to check memory location or address of two objects are same or not.
When we talk about equals() method the main purpose is to compare the state of two objects or contents of the object. But there is one relation between this two is default implementation of equals() method work like == means it will check the memory reference of the object if they point to the same location then two objects are equals and it is defined in Object class.
As we know java.lang.Object class is parent for every other object so default implementation is common for every object but if we want to override the method and want to give own implementation for checking the equality of two objects we can do, and most of the Java classes have their own implementation for equals method where they check the contents of the object .
Read more: https://www.java67.com/2012/11/difference-between-operator-and-equals-method-in.html#ixzz6WrdAEFz4