Java.lang Package Classes

Java Float - isInfinite() Method



The java.lang.Float.isInfinite() method is used to check whether the specified number is infinitely large in magnitude or not. The method returns true if the specified number is infinitely large in magnitude, false otherwise.

Syntax

public static boolean isInfinite(float v)

Parameters

v Specify the value to be tested.

Return Value

Returns true if the argument 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 number is infinitely large in magnitude or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating float values
    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?: " + Float.isInfinite(x));  
    System.out.println("Is y infinite?: " + Float.isInfinite(y)); 
    System.out.println("Is z infinite?: " + Float.isInfinite(z));  
  }
}

The output of the above code will be:

Is x infinite?: false
Is y infinite?: true
Is z infinite?: false

❮ Java.lang - Float

5