The isInfinite() method in Float Class is a built in method in Java returns true if this Float value or the specifies float value is infinitely large in magnitude, false otherwise.
Syntax:
public boolean isInfinite()
or
public static boolean isInfinite(float val)
Parameters: The function accepts a single parameter val which specifies the value to be checked when called directly with the Float class as static method. The parameter is not required when the method is used as instance method.
Return Value: It return true if the val is infinit else it return false.
Below programs illustrate isInfinite() method in Java:
Program 1: Using static isFinity() method
// Java code to demonstrate // Float isInfinite() method // without parameter class GFG { public static void main(String[] args) { // first example Float f1 = new Float(1.0 / 0.0); boolean res = f1.isInfinite(); // printing the output if (res) System.out.println(f1 + " is infinity"); else System.out.println(f1 + " is not infinity"); // second example f1 = new Float(0.0 / 0.0); res = f1.isInfinite(); // printing the output if (res) System.out.println(f1 + " is infinity"); else System.out.println(f1 + " is not infinity"); } } |
Infinity is infinity NaN is not infinity
Program 2: Using non-static isFinity() method
// Java code to demonstrate // Float isInfinite() method // with parameter class GFG { public static void main(String[] args) { // first example Float f1 = new Float(1.0 / 0.0); boolean res = f1.isInfinite(f1); // printing the output if (res) System.out.println(f1 + " is infinity"); else System.out.println(f1 + " is not infinity"); // second example f1 = new Float(0.0 / 0.0); res = f1.isInfinite(f1); // printing the output if (res) System.out.println(f1 + " is infinity"); else System.out.println(f1 + " is not infinity"); } } |
Infinity is infinity NaN is not infinity
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#isInfinite()
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Double isInfinite() method in Java with examples
- Java Guava | Floats.indexOf(float[] array, float target) method with Examples
- Java Guava | Floats.indexOf(float[] array, float[] target) method with Examples
- Float intValue() method in Java with examples
- Float compare() Method in Java with Examples
- Float byteValue() method in Java with Examples
- Float parseFloat() method in Java with examples
- Float isNaN() method in Java with examples
- Float floatToIntBits() method in Java with examples
- Float equals() method in Java with examples
- Float shortValue() method in Java with examples
- Float hashCode() method in Java with examples
- Float compareTo() method in Java with examples
- Float floatToRawIntBits() method in Java with examples
- Float doubleValue() method in Java with examples
- PrintStream print(float) method in Java with Examples
- PrintWriter println(float) method in Java with Examples
- PrintStream println(float) method in Java with Examples
- PrintWriter print(float) method in Java with Examples
- Float longValue() in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

