devxlogo

The Difference between “==” and “equals”

The Difference between “==” and “equals”

The basic difference between the “==” and the “equals” method is to compare the two entities on either side of the operator or the method. But when objects are compared, the “==” checks for the memory address equality while the “equals” method checks the content equality. If the equals method is used as such, it will just compare the address equality (which is the function of the “==” operator). Hence to make the equals method compare the content it has to be overridden (either at API level or at the user code level). Basically, if class A is not overriding the equals method then:

 	A a = new A();A b = new A();

a.equals(b) and a==b will return false as their memory addresses are different. Whereas if the equals method is overridden in class A to implement the comparing algorithm the result is:

 a.equals(b)       will return truea==b              will return false
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist