Java Float - isInfinite() Method
The java.lang.Float.isInfinite() method is used to check whether this Float value is infinitely large in magnitude or not. The method returns true if this Float 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.Float.isInfinite() method is used to check whether the given Float value is infinitely large in magnitude or not.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating Float value Float x = 5.2f; Float y = 1.0f/0.0f; Float z = Float.NaN; //checking Float 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 - Float