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));
}
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources