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.
public static int compare(char a, char b)
Parameters: This method accepts two parameters:
- a: which is the first char object to be compared.
- b: which is the second char 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 have any exception.
Comparing c and c : 0
Comparing d and D : 32
Comparing E and c : -30