What is Double.isInfinite() in Java?

Overview

The isInfinite() method of the Double class returns true if the specified number is infinite in magnitude, and returns false if otherwise.

Method signature

public static boolean isInfinite(double v)

Parameters:

double v: The value to be tested.

Example

In the code below, two Double values are defined. Both are the results of division by zero. The results are checked for infinity using the Double.isInfinite() method.

import java.lang.Double;
public class Main {
public static void main(String args[])
{
Double d1 = 1.0 / 0.0;
Double d2 = 0/0.0;
System.out.println(d1 + " - " + Double.isInfinite(d1));
System.out.println(d2 + " - " + Double.isInfinite(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