Ints.compare() is a method of Ints class in Guava library which is used to compare the two given int values. It takes two integers as parameters that are to be compared. It returns a comparator value based on the comparison of the specified integers.
public static int compare(int a, int b)
Parameters: This method takes two paramters:
- a: which is the first integer value to be compared.
- b: which is the second integer value to be compared.
Return Value: 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’
Below programs illustrate the use of the above method:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.