Table of Contents

What does the equals method in Java?

About

The equals method is the the equality operator.

In java, if two objects are equal, they must have the same hashCode()

.

Usage

In a set implementation, it's used to be sure that there will be no duplicate objects.

Utility

org.apache.commons.lang.builder

package org.apache.commons.lang.builder;
EqualsBuilder comparator = new EqualsBuilder();
// Note that this compares case sensitive
comparator.append(name, other.name);
comparator.append(..., other....);
return comparator.isEquals();