java.lang.Float isInfinite() and isInfinite(float f)

Description

The isInfinite() method of Float class is use to check if this Float object is infinite floating point. There are two isInfinite() method available to Float class which basically serve the same purpose its just that one is non static and the other is static. They would only differ on how they are being called, but it basically evaluate as the same. The following are the description for each method

  1. isInfinite() – Returns true if this Float value is infinitely large in magnitude, false otherwise.
  2. isInfinite(float f) – Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

Method Syntax

The following are the two isInfinite method of Float class

1.

public boolean isInfinite()

2.

public static boolean isFinite(float f)

Compatibility

Java 1.0

Java Float isInfinite() Example

Below is a simple java example on the usage of isInfinite() method of Float class.

package com.javatutorialhq.java.examples;

import java.util.Scanner;

import static java.lang.System.*;

/*
 * This example source code demonstrates the use of 
 * isInfinite() method of Float class.
 */

public class FloatIsInfiniteExample {

	public static void main(String[] args) {
		
		// Ask user input
		System.out.print("Enter Desired Value:");
		// declare the scanner object
		Scanner scan = new Scanner(System.in);
		// use scanner to get value from user console
		Float userInput = scan.nextFloat();
		// close the scanner object
		scan.close();		
		// check if the float input is inFinite 
		boolean check = userInput.isInfinite();
		out.println("is the value entered infinite? " + check);
		
	}

}

Basically on the above example, we just ask for user input on the console and then we use the scanner object to get the float input. After that we assign the value to an Float wrapper class and we then we check if the user input is an infinite floating point number.

Sample Output

Below is the sample output when you run the above example.

Float isInfinite() Sample Output