The difference is the Objects.equals() considers two nulls to be "equal". The pseudo code is:

  1. if both parameters are null or the same object, return true
  2. if the first parameter is null return false
  3. return the result of passing the second parameter to the equals() method of the first parameter

This means it is "null safe" (non null safe implementation of the first parameter’s equals() method notwithstanding).

Answer from Bohemian on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Object.html
Object (Java Platform SE 8 )
April 21, 2026 - The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
🌐
Medium
medium.com › @AlexanderObregon › javas-objects-equals-method-explained-3a84c963edfa
Java’s Objects.equals() Method Explained | Medium
February 23, 2026 - Explore Java's Objects.equals() method, a null-safe solution for object comparison. Learn how it prevents NullPointerException and simplifies your code.
🌐
Reddit
reddit.com › r/learnjava › confused on how equals() method works for objects and strings.
r/learnjava on Reddit: Confused on how equals() method works for objects and strings.
November 17, 2018 -

//Suppose I have another class with a default constructor method

public Circle(double r)

{

radius =r;

}

//and in my main class I have the codes

Circle cir1= new Circle(5.1);

Circle cir2= new Circle(5.1);

System.out.println(cir1.equals(cir2));

// Why would the output be false? If i use the equals() method to compare the content of two strings, then why wouldnt it work the same way when comparing the contents with two different objects? How is the output false if the arguments are the same?

Top answer
1 of 4
12
The default implementation of equals does an object comparison, so your cir1.equals... is checking to see if they're the same (not just the same values). String, for instance, overrides the default equals method to check against the value not the object itself. You can override the equals method on your circle object to compare based on value (radius). More info
2 of 4
3
First of all, the objects aren't "the same" (which is why the default equals method returns false). They live in different places in memory so they the computer treats them as different objects. However, they are "equal." If you want the equals method to check for that equality then you have to implement it yourself. Here is some very bad code that isn't going to compile but maybe it's demonstrative anyway: public class Circle { private double radius; public Circle(double aRadius) { radius = aRadius; } public boolean equals(Circle c) { return this.radius == c.radius; } } The idea is that you have to tell the compiler what it should mean for two circles to be equal. In this case, you want to check that the radii are equal. That code is bad for several reasons, though. First, the equals method must take an Object as its argument (because you're overriding another method). Second, c.radius isn't going to work because radius is private (or at least it should be). Third, it is bad practice to check equality of doubles (more on this in a bit). Here is better code: public class Circle { private double radius; public Circle(double aRadius) { radius = aRadius; } public boolean getRadius() { return radius; } public boolean equals(Object o) { // this checks if this object and o are *actually* the same. if (o == this) { return true; } // Here we return false if o isn't actually a Circle object. if (!(o instanceof Circle)) { return false; } // If the code gets to this point we can safely assume that o is actually // a circle and we can do the radius check. Circle c = (Circle) o; return radius == c.getRadius(); } } The code above should do what you're describing but I still didn't address the "it is bad practice to check equality of doubles" issue. The problem is that the line return radius == c.getRadius(); isn't really going to work how you think. There is a lot of rounding involved in floating point computations and sometimes numbers that you think should be equal aren't going to be equal. There are several ways to handle this but the general idea is that you should invent some kind of "tolerance" where doubles that are within the tolerance of each other are considered equal. Something like this: Circle c = (Circle) o; double difference = radius - c.getRadius(); return (difference < 0.000000000001) && (difference > -0.000000000001); This code checks that the difference between radius and c.getRadius() is between 0.000000000001 and -0.000000000001. This still isn't the best; you shouldn't use a magic number like 0.000000000001 (instead there should be a global TOLERANCE variable) and there are already methods in the world to handle the comparison of doubles so it's probably better to use one of those but this isn't a thread about comparing doubles so I won't get into it any further.
🌐
CloudBees
cloudbees.com › blog › benchmarking-different-approaches-equality-java
Benchmarking Different Approaches to Equality in Java
At some point, however, you will come to a decision and decide that two objects are equal if a defined list of properties of the object are equal. Now the time has come to actually write the equals(Object) method.
🌐
InfoWorld
infoworld.com › home › blogs › java challengers
Comparing Java objects with equals() and hashcode() | InfoWorld
May 16, 2024 - Java’s equals() and hashcode() are two methods that work together to verify if two objects have the same value.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Objects.html
Objects (Java Platform SE 8 )
April 21, 2026 - Otherwise, equality is determined by using the equals method of the first argument. ... Returns the hash code of a non-null argument and 0 for a null argument. ... Generates a hash code for a sequence of input values. The hash code is generated as if all the input values were placed into an ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › equals-hashcode-methods-java
equals() and hashCode() methods in Java - GeeksforGeeks
July 23, 2025 - equals() method In java equals() method is used to compare equality of two Objects.
🌐
Medium
medium.com › dev-java › java-best-practice-why-and-should-not-replace-equals-for-object-comparison-834cd7ccb0a9
Java Best Practice: Why == and != Should Not Replace equals() for Object Comparison | by Anil R | Dev Java | Medium
April 28, 2025 - Java Best Practice: Why == and != Should Not Replace equals() for Object Comparison n Java, developers often use == and != to compare objects, but this can lead to subtle bugs and incorrect program …
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-compare-two-objects
Java Program to Compare Two Objects - GeeksforGeeks
July 23, 2025 - Therefore, it is advisable not to use this method in comparing objects without overriding it. Implementing the equals method for the before example: ... // Java Program to Compare Two Objects import java.io.*; class Pet { String name; int age; String breed; Pet(String name, int age, String breed) { this.name = name; this.age = age; this.breed = breed; } @Override public boolean equals(Object obj) { // checking if the two objects // pointing to same object if (this == obj) return true; // checking for two condition: // 1) object is pointing to null // 2) if the objects belong to // same class o
🌐
Programiz
programiz.com › java-programming › library › object › equals
Java Object equals()
The equals() method takes a single parameter. obj - object which is to be compared with the current object ... Note: In Java, if two reference variables refer to the same object, then the two reference variables are equal to each other.
🌐
Medium
medium.com › @sunil17bbmp › mastering-equals-and-hashcode-in-java-a-complete-guide-to-object-identity-c147d23d6c2c
Mastering equals() and hashCode() in Java: A Complete Guide to Object Identity | by Code With Sunil | Code Smarter, not harder | Medium
September 27, 2025 - In Java, the equals() and hashCode() methods are defined in the Object class, which means every Java class inherits a default implementation of these methods.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-equals-compareto-equalsignorecase-and-compare
Java | ==, equals(), compareTo(), equalsIgnoreCase() and compare() - GeeksforGeeks
January 22, 2026 - The == operator compares object references, not the actual content of the strings. It returns true only if both references point to the same memory location.Strings created without the new keyword are stored in the String Constant Pool, so they ...
🌐
AWS
docs.aws.amazon.com › AWSJavaSDK › latest › javadoc › com › amazonaws › services › elasticloadbalancing › model › SetLoadBalancerPoliciesForBackendServerResult.html
SetLoadBalancerPoliciesForBackendServerResult (AWS SDK for Java - 1.12.797)
@Generated(value="com.amazonaws:aws-java-sdk-code-generator") public class SetLoadBalancerPoliciesForBackendServerResult extends AmazonWebServiceResult<ResponseMetadata> implements Serializable, Cloneable · Contains the output of SetLoadBalancerPoliciesForBackendServer. ... Returns a string representation of this object...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
April 21, 2026 - public boolean contains(Object o) Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
🌐
TC39
tc39.es › ecma262
ECMAScript® 2027 Language Specification
1 week ago - ECMAScript 2021, the 12th edition, introduced the replaceAll method for Strings; Promise.any, a Promise combinator that short-circuits when an input value is fulfilled; AggregateError, a new Error type to represent multiple errors at once; logical assignment operators (??=, &&=, ||=); WeakRef, for referring to a target object without preserving it from garbage collection, and FinalizationRegistry, to manage registration and unregistration of cleanup operations performed when target objects are garbage collected; separators for numeric literals (1_000); and Array.prototype.sort was made more precise, reducing the amount of cases that result in an
🌐
LinkedIn
linkedin.com › all › object oriented design
How do you implement the equals and hashCode methods in Java to ensure object equality?
April 17, 2023 - Identity means that two objects are the same instance, which can be checked with the == operator. Equality means that two objects have the same state or value, which can be checked with the equals method.