Java Float.compareTo(Float anotherFloat)

Syntax

Float.compareTo(Float anotherFloat) has the following syntax.

public int compareTo(Float anotherFloat)

Example

In the following code shows how to use Float.compareTo(Float anotherFloat) method.

The following code illustrates how to create NaN in float and compares to another float type value.


public class Main {
  public static void main(String[] args) {
    Float floatObject1 = new Float("10.0001");
    /* w w  w  . ja va  2s .  c  om*/
    Float floatObject2 = Float.valueOf((float)0.0/(float)(0.0));
    System.out.println(floatObject2);
    
    System.out.println(floatObject1.compareTo(floatObject2));
    
  }
}

The output:





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable