Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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:
Byte equals() method in Java with examples
Next article icon

Double.equals() Method in Java with Examples

Last Updated : 19 Jun, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

The java.lang.Double.equals() is a built-in function in java that compares this object to the specified object. 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. It returns false if both the objects are not same. In all other cases, compareTo method should be preferred.

Syntax:

  public boolean equals(Object obj)  

Parameter: The method accepts only one parameter.
obj – The passed object is the object that is to be compared with.

Return Values: The function returns a boolean value after comparing 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 same.

Below programs illustrates the use of java.lang.Double.equals() method:

Program 1:




// Java program to demonstrate
// of java.lang.Double.equals() method
import java.lang.*;
  
class Gfg1 {
  
    public static void main(String args[])
    {
  
        // When two objects are different
        Double obj1 = new Double(123123);
        Double obj2 = new Double(164165);
        System.out.print("Object1 & Object2: ");
        if (obj1.equals(obj2))
            System.out.println("Equal");
        else
            System.out.println("Not equal");
  
        // When two objects are equal
        obj1 = new Double(12345);
        obj2 = new Double(12345);
        System.out.print("Object1 & Object2: ");
        if (obj1.equals(obj2))
            System.out.print("Equal");
        else
            System.out.print("Not Equal");
    }
}
 
 
Output:
  Object1 & Object2: Not equal  Object1 & Object2: Equal  

Program 2: When no argument is passed.




// Java program to demonstrate
// of java.lang.Double.equals() method
import java.lang.Math;
  
class Gfg1 {
  
    // Driver code
    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:

  prog.java:15: error: no suitable method found for equals(no arguments)          if (obj1.equals())                  ^      method Object.equals(Object) is not applicable        (actual and formal argument lists differ in length)      method Double.equals(Object) is not applicable        (actual and formal argument lists differ in length)  1 error  

Program 3: When anything other than the object is passed as an argument.




// Java program to demonstrate
// of java.lang.Double.equals() method
import java.lang.Math;
  
class Gfg1 {
  
    // Driver code
    public static void main(String args[])
    {
  
        // When anything other than the argument is passed
        Double obj1 = new Double(124);
  
        System.out.print("Object1 & Object2: ");
        if (obj1.equals("gfg"))
            System.out.println("Equal");
        else
            System.out.println("Not Equal");
    }
}
 
 
Output:
  Object1 & Object2: Not Equal  


Next Article
Byte equals() method in Java with examples

T

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

Similar Reads

  • Byte equals() method in Java with examples
    The equals() method of Byte class is a built in method in Java which is used to compare the equality given Object with the instance of Byte invoking the equals() method. Syntax ByteObject.equals(Object a) Parameters: It takes an Object type object a as input which is to be compared with the instance
    2 min read
  • DoubleBuffer equals() method in Java with Examples
    The equals() method of java.nio.DoubleBuffer Class is used to check whether or not the given buffer is equal to another object. Two double 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,
    3 min read
  • Date equals() method in Java with Examples
    The equals() method of Java Date class checks if two Dates are equal, based on millisecond difference. Syntax: public boolean equals(Object obj) Parameters: The function accepts a single parameter obj which specifies the object to be compared with. Return Value: The function gives 2 return values sp
    2 min read
  • Boolean equals() method in Java with examples
    The equals() method of Boolean class is a built in method of Java which is used check equality of two Boolean object. Syntax: BooleanObject.equals(Object ob) Parameter: It take a parameter ob of type Object as input which is the instance to be compared. Return Type: The return type is boolean. It re
    2 min read
  • BitSet equals() Method in Java with Examples
    The equals() method of Java BitSet class is used to check for equality between two bitsets. It verifies whether the elements of one set passed as a parameter is equal to the elements of this set or not. The method returns true if the bitsets match else false. Syntax: Bit_Set1.equals(Bit_Set2) Parame
    2 min read
  • Double doubleValue() method in Java with examples
    The doubleValue() method of Double class is a built in method to return the value specified by the calling object as double after type casting. Syntax: DoubleObject.doubleValue() Return Value: It return the value of DoubleObject as double. Below programs illustrate doubleValue() method in Java: Prog
    2 min read
  • CompoundName equals() method in Java with Examples
    The equals() method of a javax.naming.CompoundName class is used to compare this CompoundName with the specified object passed as a parameter and checks whether two objects are equal or not. If both objects are equal then the equals() method returns true else false. If passed obj is null or not a co
    2 min read
  • Charset equals() method in Java with Examples
    The equals() method is a built-in method of the java.nio.charset checks if a given object of charset is equal to another given object of the charset. Two charsets are considered equal if, and only if, they have the same canonical names. A charset is never equal to any other type of object. Syntax: p
    2 min read
  • DateFormat equals() Method in Java with Examples
    The equals() Method of the DateFormat class is used to compare two DateFormat objects. The method returns True if this DateFormat is equal to the passed object else returns False. Syntax: public boolean equals(Object obj) Parameters: The method takes one parameter obj of Object type and refers to th
    2 min read
  • ByteBuffer equals() method in Java with Examples
    The equals() method of java.nio.ByteBuffer class is used to check whether or not the given buffer is equal to another object. Two byte 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
    3 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