Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


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 below example, 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 = new Float("5.2f");
    Float y = new Float(1.0/0.0);
    Float z = new 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