What is Double.isFinite() in Java?

Overview

The isFinite() method of the Double class returns true if the argument is a finite floating-point value, and returns false otherwise (for NaN and infinity arguments).

Method signature

public static boolean isFinite(double d)

Parameters

  • double d: the value to be tested.

Example

In the example below, we define two double values. One is an exponential number, and the other is the result of division by zero. The two double values are tested by the Double.isFinite() method.

import java.lang.Double;
public class Main {
public static void main(String args[])
{
Double d1 = 2E23;
Double d2 = d1/0;
System.out.println(d1 + " - " + Double.isFinite(d1));
System.out.println(d2 + " - " + Double.isFinite(d2));
}
}

Free Resources