Java Float.compare(float f1, float f2)

Syntax

Float.compare(float f1, float f2) has the following syntax.

public static int compare(float f1,  float f2)

Example

In the following code shows how to use Float.compare(float f1, float f2) method.

The code below uses the compareTo(Float anotherFloat) method to compare two Float objects.


public class Main {
  public static void main(String[] args) {
    Float floatObject1 = new Float("10.0001");
    Float floatObject2 = new Float("10.0002");
    /* w w w.j  ava 2s .  com*/
    System.out.println(Float.compare(floatObject1,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