Java Guava | Floats.compare() method with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report Floats.compare() method of Floats Class is used to compare the two specified float values. These values are passed as the parameter and the result of comparison is found as the difference of 1st value and the 2nd value. Hence it can be positive, zero or negative. Syntax: public static int compare(float a, float b) Parameters: This method accepts two parameters: a: which is the first float object to be compared. b: which is the second float object to be compared. Return type: This method returns an int value. It returns: 0 if ‘a’ is equal to ‘b’, a positive value ‘a’ is greater than ‘b’, a negative value ‘a’ is lesser than ‘b’ Exceptions: The method does not throw any exception. Example 1: Java // Java code to show implementation of // Guava's Floats.compare() method import com.google.common.primitives.Floats; class GFG { public static void main(String[] args) { float a = 4f; float b = 4f; // compare method in Float class int output = Floats.compare(a, b); // printing the output System.out.println("Comparing " + a + " and " + b + " : " + output); } } Output: Comparing 4.0 and 4.0 : 0 Example 2: Java // Java code to show implementation of // Guava's Floats.compare() method import com.google.common.primitives.Floats; class GFG { public static void main(String[] args) { float a = 4.2f; float b = 3.1f; // compare method in Float class int output = Floats.compare(a, b); // printing the output System.out.println("Comparing " + a + " and " + b + " : " + output); } } Output: Comparing 4.2 and 3.1 : 1 Example 3: Java // Java code to show implementation of // Guava's Floats.compare() method import com.google.common.primitives.Floats; class GFG { public static void main(String[] args) { float a = 2.5f; float b = 4f; // compare method in Float class int output = Floats.compare(a, b); // printing the output System.out.println("Comparing " + a + " and " + b + " : " + output); } } Output: Comparing 2.5 and 4.0 : -1 Comment More infoAdvertise with us Next Article Java Guava | Floats.compare() method with Examples S Sahil_Bansall Follow Improve Article Tags : Java Java-Functions java-guava Guava-Floats Practice Tags : Java Similar Reads Float compare() Method in Java with Examples The compare() method of Float Class is a built-in method in Java that compares the two specified float 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(float f1, float f2)Parameters: The f 2 min read Float compareTo() method in Java with examples The comapreTo() method of Float Class is a built-in method in Java that compares the two specified float 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 int compareTo(Object f) Parameters: The function acce 2 min read Java Guava | Floats.asList() method with Examples The Floats.asList() method of Guava's Floats Class accepts a float array as a parameter and returns a list which has the fixed size. The returned list is backed by the float array which is passed as the argument. It means the changes made in the array passed as parameter will be reflected back in th 2 min read Java Guava | Longs.compare() method with Examples Longs.compare() method of Guava's Longs Class is used to compare the two specified long values. These values are passed as the parameter and the result of comparison is found as the difference of 1st value and the 2nd value. Hence it can be positive, zero or negative. Syntax: public static int compa 2 min read Java Guava | Chars.compare() method with Examples Chars.compare() method of Guava's Chars Class is used to compare the two specified char values. These values are passed as the parameter and the result of comparison is found as the difference of 1st value and the 2nd value. Hence it can be positive, zero or negative. Syntax: public static int compa 2 min read Like