Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
BigInteger equals() Method in Java
Next article icon

Java Double.equals() Method

Last Updated : 14 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Double.equals() in Java is a built-in function from the java.lang.Double class. This method compares the content of two Double objects. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. This method is useful for checking equality, while the compareTo method is better for ordering or sorting purposes.

Syntax of Double.equals() Method

public boolean equals(Object obj)

  • Parameter: obj: This is the object to be compared.
  • Return Values: The function returns a boolean value after comparing it with the object passed in the parameter. It returns "true" if and only if the argument is not null and is a Double object that contains the same double value as this object. It returns "false" if the object is not the same.

Examples of Java Double.equals() Method

Example 1: In this example, we are going to compare two Double objects.

Java
// Java program to demonstrate  // Double.equals() with valid comparisons import java.lang.Double;  public class Geeks {      public static void main(String[] args) {          // create two Double objects          // with different values         Double n1 = new Double(100.25);         Double n2 = new Double(200.75);          // compare them using equals()         if (n1.equals(n2)) {             System.out.println("n1 and n2 are equal.");         } else {             System.out.println("n1 and n2 are not equal.");         }          // create two Double objects          // with the same value         Double n3 = new Double(99.99);         Double n4 = new Double(99.99);          // Compare them         if (n3.equals(n4)) {             System.out.println("n3 and n4 are equal.");         } else {             System.out.println("n3 and n4 are not equal.");         }     } } 

Output
n1 and n2 are not equal. n3 and n4 are equal. 


Example 2: In this example, we will see what happens when anything other than the object is passed as an argument.

Java
// Java program to demonstrate  // Double.equals() with invalid arguments import java.lang.Double;  public class Geeks {      public static void main(String[] args) {          Double v = new Double(55.55);          // compare with a string         if (v.equals("Education")) {             System.out.println("Equal to string.");         } else {             System.out.println("Not equal to string.");         }          // compare with null         if (v.equals(null)) {             System.out.println("Equal to null.");         } else {             System.out.println("Not equal to null.");         }     } } 

Output
Not equal to string. Not equal to null. 


Example 3: In this example, we will see what happens when no argument is passed.

Java
// Java program to demonstrate incorrect  // use of Double.equals() without an argument import java.lang.Math;  public class Geeks {      public static void main(String args[])     {          // When no argument is passed         Double obj1 = new Double(124);         Double obj2 = new Double(167);                  System.out.print("Object1 & Object2: ");         if (obj1.equals())             System.out.println("Equal");         else             System.out.println("Not Equal");     } } 

Output:

error: method equals in class Double cannot be applied to given types;
if (obj1.equals())
^
required: Object
found: no arguments
reason: actual and formal argument lists differ in length

Note: The equals() method requires a single argument. If no argument is there, it will cause compile-time error.


Next Article
BigInteger equals() Method in Java

T

Twinkl Bajaj
Improve
Article Tags :
  • Java
  • Java-lang package
  • Java-Functions
  • Java-Double
Practice Tags :
  • Java

Similar Reads

    Java Map equals() Method
    The equals() method of Map interface in Java is used to check if two maps are equal. Two maps are considered equal if they meet the following conditions. Both maps must have the same size.Both maps must contain identical key-value pairs. (It means every key in one map must be associated with the sam
    2 min read
    Java AbstractSet equals() Method
    The AbstractSet equals() Method in Java is used to check for equality between two sets. This method verifies whether the elements of one set are equal to the elements of another set.Syntax of AbstractSet equals() Methodpublic boolean equals(Object o)Parameter: The object "o" is to be compared for eq
    1 min read
    Double.equals() Method in Java with Examples
    The Double.equals() in Java is a built-in function from the java.lang.Double class. This method compares the content of two Double objects. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. This method is useful for
    3 min read
    BigInteger equals() Method in Java
    The java.math.BigInteger.equals(Object x) method compares this BigInteger with the object passed as the parameter and returns true in both are equal in value else it returns false. Syntax: public boolean equals(Object x) Parameter: This method accepts a single mandatory parameter x which is the Obje
    3 min read
    CharBuffer equals() method in Java
    The equals() method of java.nio.CharBuffer Class is used to check whether or not the given buffer is equal to another object. Two char buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, con
    4 min read
    Set equals() Method in Java
    In Java, the equals() method of the Set class is used to compare two sets for equality. It checks if two sets contain the same elements regardless of their order.Example 1: This example demonstrates how to compare two HashSet collections for equality of type string using the equals() method.Java// J
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences