java.lang.Double isInfinite()

Syntax:

public static boolean isInfinite()

Java Code Example :

This java example source code demonstrates the use of isInfinite() method of Double class.  This method returns true if this Double value is infinitely large in magnitude, false otherwise.

On this example we will evaluate numbers and check if the values are infinite or not.

package com.javatutorialhq.java.examples;

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

public class DoubleIsInfinite {

	public static void main(String[] args) {
		
		// declare values to be evaluated
		Double val1 = 25.3 / 0.0;
		Double val2 = -25.25 / 0.0;
		Double val3 = 30.1832;
		Double val4 = val3 / 0.0;
		Double val5 = val1 / val2;
		
		// check the values if value is infinite
		System.out.println(val1 + " isInfinite: " + val1.isInfinite());
		System.out.println(val2 + " isInfinite: " + val2.isInfinite());
		System.out.println(val3 + " isInfinite: " + val3.isInfinite());
		System.out.println(val4 + " isInfinite: " + val4.isInfinite());
		System.out.println(val5 + " isInfinite: " + val5.isInfinite());

	}

}

Sample Output :

Running the above example source code will give the following output

Infinity is not a number?false
-Infinity is not a number?false
25.112 is not a number?false
NaN is not a number?true
NaN is not a number?true

Suggested Reading List :

References :