Java Guava | Floats.compare() method with Examples
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.
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.
Comparing 4.0 and 4.0 : 0
Comparing 4.2 and 3.1 : 1
Comparing 2.5 and 4.0 : -1