Java Data Type Tutorial - 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");
    
    System.out.println(Float.compare(floatObject1,floatObject2));
    
  }
}

The output: