Java Double - isInfinite() Method
The java.lang.Double.isInfinite() method is used to check whether this Double value is infinitely large in magnitude or not. The method returns true if this Double value is infinitely large in magnitude, false otherwise.
Syntax
public boolean isInfinite()
Parameters
No parameter is required.
Return Value
Returns true if the value represented by this object 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 Double value is infinitely large in magnitude or not.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating Double value 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?: " + x.isInfinite()); System.out.println("Is y infinite?: " + y.isInfinite()); System.out.println("Is z infinite?: " + z.isInfinite()); } }
The output of the above code will be:
Is x infinite?: false Is y infinite?: true Is z infinite?: false
❮ Java.lang - Double