Java.lang Package Classes

Java Double - isInfinite() Method



The java.lang.Double.isInfinite() method is used to check whether the specified number is infinitely large in magnitude or not. The method returns true if the specified number is infinitely large in magnitude, false otherwise.

Syntax

public static boolean isFinite(double d)

Parameters

d Specify the value to be tested.

Return Value

Returns true if the argument is positive infinity or negative infinity; false otherwise.

Exception

NA.

Example:

In the example below, the java.lang.Double.isInfinite() method is used to check whether the given number is infinitely large in magnitude or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating double values
    double x = 5.2;
    double y = 1.0/0.0;
    double z = Double.NaN;

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

The output of the above code will be:

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

❮ Java.lang - Double

5