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
🌐
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.
Discussions

How does Java "==" operator check equality between objects? Trying to understand how Object.equals() works
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
20
1
January 8, 2023
== vs. .equals()??
== will just check if the two arguments have the same memory reference while an object's equals() class method checks some internal value to determine equivalence (when you create your own classes, you may implement a custom equals() method). public static void main(String []args){ Object a = new Object(); Object b = a; Object c = new Object(); System.out.println("a == b ? "+ (a == b) ); //true System.out.println("a == c ? "+ (a == c) ); //false System.out.println("a.equals(b) ? "+ a.equals(b)); //true } Every object is a subtype of Object, so (generally) you can pass a Song where the documentation expects Object. More on reddit.com
🌐 r/learnjava
24
32
July 3, 2020
Help me understand the difference between "==" and ".equals()" in Java
From what I've gathered so far, they seem to do the same thing - is it true? No. They don't do the same thing. .equals() is a method, so it only applies to objects (reference types). The method compares the content of an object to another. == is an operator - a test for equality on primitive types and for identity (being the same) for objects (reference types). Generally, you should always use .equals with objects - including String values (they also are objects). The exception is if you want to test if two objects (actually their object references) are identical (have the same reference). More on reddit.com
🌐 r/learnjava
24
26
July 15, 2025
Java comparison == is not null-safe?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
41
16
February 21, 2024
🌐
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 ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › object_equals.htm
Java Object equals() Method
The Java Object equals(Object obj) method indicates whether some other object is "equal to" this one. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference
🌐
Educative
educative.io › answers › what-is-objectsequals-in-java
What is Objects.equals in Java?
The equals() method is a static method of the Objects class that accepts two objects and checks if the objects are equal.
🌐
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).
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › core java › comparing objects in java
Comparing Objects in Java | Baeldung
May 22, 2020 - This method is defined in the Object class so that every Java object inherits it. By default, its implementation compares object memory addresses, so it works the same as the == operator.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Object › equals
Java Object equals() - Compare Objects Equality | Vultr Docs
November 15, 2024 - The equals() method in Java is a fundamental mechanism for comparing two objects for equality. It plays a crucial role in collections, such as HashSet and HashMap, that rely on equality checks to function correctly.
🌐
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.
🌐
Reddit
reddit.com › r/learnjava › == vs. .equals()??
r/learnjava on Reddit: == vs. .equals()??
July 3, 2020 -

I'm on MOOC.fi and I'm a little confused on why you can't use .equals() when comparing two objects. And on part 5_12.Song programming exercise, I'm confused on why the parameter takes an Object parameter instead of a "Song" type, and then why do we have to typecast the object to compare it?

🌐
JetBrains
jetbrains.com › help › inspectopedia › ObjectsEqualsCanBeSimplified.html
'Objects.equals()' can be replaced with 'equals()' | Inspectopedia Documentation
Such a call can be safely replaced with a.equals(b) or a == b if both arguments are primitives. ... Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings. ... Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE. Settings or Preferences | Editor | Inspections | Java | Code style issues
🌐
Stack Abuse
stackabuse.com › javas-object-methods-equals-object
Java's Object Methods: equals(Object)
March 22, 2019 - Ok, it should be evident that Person now has a much more robust equals(Object) implementation. Now let me give an example of how inheritance can cause a violation of symmetry. Below is a seemingly harmless class, called Employee, that inherits from Person. import java.time.LocalDate; public class Employee extends Person { private String department; public Employee(String firstName, String lastName, LocalDate dob, String department) { super(firstName, lastName, dob); this.department = department; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Employee)) { return false; } Employee p = (Employee)o; return super.equals(o) && department.equals(p.department); } }
🌐
Reddit
reddit.com › r/learnjava › help me understand the difference between "==" and ".equals()" in java
r/learnjava on Reddit: Help me understand the difference between "==" and ".equals()" in Java
July 15, 2025 -

I'm currently working on a project that involves comparing strings, but I keep getting stuck on whether to use the "==" operator or the ".equals()" method. From what I've gathered so far, they seem to do the same thing - is it true? Or are there cases where one should be used over the other?

Top answer
1 of 5
49
From what I've gathered so far, they seem to do the same thing - is it true? No. They don't do the same thing. .equals() is a method, so it only applies to objects (reference types). The method compares the content of an object to another. == is an operator - a test for equality on primitive types and for identity (being the same) for objects (reference types). Generally, you should always use .equals with objects - including String values (they also are objects). The exception is if you want to test if two objects (actually their object references) are identical (have the same reference).
2 of 5
38
The difference is a bit hard to explain using strings, so let's use cars instead! Imagine you and your neighbor both own the same car - two different objects but same manufacturer, same color, same number of seats and so on. .equals() will be true because both these cars share the same properties.  However, == will be false because it's two different cars parking in two different parking lots. Let's say you have a daughter and she's learning to drive. For this reason, you allow her to use your car. You set herCar = yourCar. This means herCar == yourCar because both terms/variables ("herCar" and "yourCar") POINT to the exact same car. If you ask someone to point his finger to her car, he'll point at exactly the same car as when you ask him to point at yours. Another example: if someone hits your car with a stone, causing a bruise, this bruise will also exist on your daughter's car because it is the exact same vehicle. However there won't be a bruise on your neighbor's car because yours and his only equal, but they don't ==. Let's go back to strings: .equals() checks whether the strings look the same, have the same length and consist of the same characters in the same order. == checks whether two strings are stored on the same position inside your computer memory. So if you have a string "ExampleString" stored in your memory several times on several positions, == will only be true if you compare variables pointing to the exact same position of the exact string in your computer memory. It will be false otherwise, even if the strings are the same text. This is the case for all objects. For this reason, you should always use equals for objects. --- tl;dr: .equals() means "does it look the same" and can return true even if it's two different objects in your computer memory. == means "is it EXACTLY the same" and can return false even if the objects are 100% equal as long as it's two different objects stored in different positions in your computer memory.
🌐
Medium
medium.com › @dr4wone › equals-vs-compareto-in-java-understanding-the-differences-fce0a0d4b292
Equals vs. compareTo in Java: Understanding the Differences | by Daniel Baumann | Medium
April 9, 2023 - The equals() method is used to compare objects for equality. It returns true if two objects are equal and false if they are not. By default, the equals() method in Java compares objects based on their memory location.
🌐
Medium
medium.com › @AlexanderObregon › why-object-equality-in-java-isnt-always-what-you-expect-2c61278d9226
Why Object Equality in Java Isn’t Always What You Expect
April 19, 2025 - When you’re working with objects in Java, it’s easy to assume that if two of them look the same, they’ll be treated as equal. But that’s not always the case. Java has its own way of deciding what counts as equal, and it depends on more than just what’s inside the object.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.objects.equals
Objects.Equals(Object, Object) Method (Java.Util) | Microsoft Learn
Otherwise, if the first argument is not null, equality is determined by calling the Object#equals equals method of the first argument with the second argument of this method. Otherwise, false is returned. Java documentation for java.util.Objects.equals(java.lang.Object, java.lang.Object).
🌐
Medium
medium.com › @alxkm › vs-equals-in-java-whats-the-difference-and-when-to-use-which-727f7f39bce7
Java Object Comparison: == vs .equals()-A Complete Guide | by Alex Klimenko | Medium
August 9, 2025 - Understanding the distinction between ... two references point to the same object, while .equals() checks if two objects are logically equivalent based on their content....
🌐
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.