Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Double.equals() method is used to compare this object against the specified object. The result is true if and only if the argument is not null and is a Double object that represents a double that has the same value as the double represented by this object.

Syntax

public boolean equals(Object obj)

Parameters

obj Specify the object to compare with.

Return Value

Returns true if the objects are the same; false otherwise.

Exception

NA.

Example:

In the below example, the java.lang.Double.equals() method is used to compare given Double objects for equality.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Double objects
    Double val1 = new Double("5.2");
    Double val2 = new Double("5.2");
    Double val3 = new Double("-5.2");

    //checking Double objects for equality
    System.out.println("Is val1 == val2?: " + val1.equals(val2)); 
    System.out.println("Is val1 == val3?: " + val1.equals(val3));    
  }
}

The output of the above code will be:

Is val1 == val2?: true
Is val1 == val3?: false

❮ Java.lang - Double