What does the equals method in Java?

Java Conceptuel Diagram

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();





Discover More
Card Puncher Data Processing
Design Pattern - (Static) Factory

The Factory pattern creates an instance of an object according to a given specification, sometimes provided as arguments, sometimes inferred. It's a dependency resolving approach. A factory class decouples...
Java Conceptuel Diagram
Java - Object (instance of a class)

An java/lang/Objectobject: stores its state in fields and exposes its behaviour through methods (functions in some programming languages). Methods operate on an object's internal state and serve...
Java Conceptuel Diagram
Java - Set (Collection)

This interface is a member of the Java Collections Framework. Set is a collection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent...
Java Conceptuel Diagram
What is the Java hashCode Method?

The Java hashCode method outputs a hash creating an unique identifier for the object. If two objects are equal, they must have the same hashCode() output. The hashCode is generally overwritten by the...



Share this page:
Follow us:
Task Runner