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


The java.lang.Double.isNaN() method is used to check whether this Double value is a Not-a-Number (NaN) or not. The method returns true if this Double value is a Not-a-Number (NaN), false otherwise.

Syntax

public boolean isNaN()

Parameters

No parameter is required.

Return Value

Returns true if the value represented by this object is NaN; false otherwise.

Exception

NA.

Example:

In the below example, the java.lang.Double.isNaN() method is used to check whether the given Double value is NaN or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Double value
    Double x = new Double("5.2");
    Double y = new Double(0.0/0.0);
    Double z = new Double("NaN");

    //checking Double values for NaN
    System.out.println("Is x NaN?: " + x.isNaN());  
    System.out.println("Is y NaN?: " + y.isNaN()); 
    System.out.println("Is z NaN?: " + z.isNaN());  
  }
}

The output of the above code will be:

Is x NaN?: false
Is y NaN?: true
Is z NaN?: true

❮ Java.lang - Double