Double isNaN() method in Java with examples Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The isNaN() method of Java Double class is a built in method in Java returns true if this Double value or the specified double value is Not-a-Number (NaN), or false otherwise. Syntax: public boolean isNaN() or public static boolean isNaN(double val) Parameters: The function accepts a single parameter val which specifies the value to be checked when called directly with the Double class as static method. The parameter is not required when the method is used as instance method. Return Value: It returns true if the val is NaN else it return false. Below programs illustrate isNaN() method in Java: Program 1: Java // Java code to demonstrate // Double isNaN() method // without parameter class GFG { public static void main(String[] args) { // first example Double f1 = new Double(1.0 / 0.0); boolean res = f1.isNaN(); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); // second example f1 = new Double(0.0 / 0.0); res = f1.isNaN(); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); } } Output: Infinity is not NaN NaN is NaN Program 2: Java // Java code to demonstrate // Double isNaN() method // with parameter class GFG { public static void main(String[] args) { // first example Double f1 = new Double(1.0 / 0.0); boolean res = f1.isNaN(f1); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); // second example f1 = new Double(0.0 / 0.0); res = f1.isNaN(f1); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); } } Output: Infinity is not NaN NaN is NaN Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#isNaN() Comment More infoAdvertise with us Next Article Double compare() Method in Java with Examples G gopaldave Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions Java-Double +1 More Practice Tags : Java Similar Reads Double intValue() method in Java with examples The intValue() method of Double class is a built in method to return the value specified by the calling object as int after type casting. Syntax: DoubleObject.intValue() Return Value: It return the value of DoubleObject as int. Below programs illustrate intValue() method in Java: Program 1: Java // 2 min read Double intValue() method in Java with examples The intValue() method of Double class is a built in method to return the value specified by the calling object as int after type casting. Syntax: DoubleObject.intValue() Return Value: It return the value of DoubleObject as int. Below programs illustrate intValue() method in Java: Program 1: Java // 2 min read Float doubleValue() method in Java with examples The doubleValue() method of Float class is a built in method to return the value specified by the calling object as double after type casting. Syntax: FloatObject.doubleValue() Return Value: It return the double value of this Float object. Below programs illustrate doubleValue() method in Java: Prog 2 min read Float doubleValue() method in Java with examples The doubleValue() method of Float class is a built in method to return the value specified by the calling object as double after type casting. Syntax: FloatObject.doubleValue() Return Value: It return the double value of this Float object. Below programs illustrate doubleValue() method in Java: Prog 2 min read Double compare() Method in Java with Examples The compare() method of Double Class is a built-in method in Java that compares the two specified double values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(double d1, double d2) Parameters: 2 min read Double compare() Method in Java with Examples The compare() method of Double Class is a built-in method in Java that compares the two specified double values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(double d1, double d2) Parameters: 2 min read Like