Java.lang Package Classes

Java Float - isFinite() Method



The java.lang.Float.isFinite() method is used to check whether the argument is a finite floating-point value or not. The method returns true if the argument is a finite floating-point value, false otherwise. The method returns false for NaN and infinity arguments.

Syntax

public static boolean isFinite(float f)

Parameters

f Specify the value to be tested.

Return Value

Returns true if the argument is a finite floating-point value, false otherwise.

Exception

NA.

Example:

In the example below, the java.lang.Float.isFinite() method is used to check whether the argument is a finite floating-point value 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 finite
    System.out.println("Is x finite?: " + Float.isFinite(x));  
    System.out.println("Is y finite?: " + Float.isFinite(y)); 
    System.out.println("Is z finite?: " + Float.isFinite(z));  
  }
}

The output of the above code will be:

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

❮ Java.lang - Float