Java Guava | Ints.compare() method with Examples
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.
Syntax :
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:
Example-1:
// Java code to show implementation of // Guava's Ints.compare() method import com.google.common.primitives.Ints; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Using Ints.compare() method to // compare the two specified int // values in the standard way // This should return positive number // as a is greater than b System.out.println(Ints.compare( 5 , 3 )); } } |
1
Example-2 :
// Java code to show implementation of // Guava's Ints.compare() method import com.google.common.primitives.Ints; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Using Ints.compare() method to // compare the two specified int // values in the standard way // This should return 0 as a == b System.out.println(Ints.compare( 2 , 2 )); } } |
0
Recommended Posts:
- Java Guava | Chars.max() method with Examples
- Java Guava | Longs.min() method with Examples
- Java Guava | Chars.min() method with Examples
- Java Guava | Chars.contains() method with Examples
- Java Guava | Floats.min() method with Examples
- Java Guava | Doubles.min() method with Examples
- Java Guava | Booleans.contains() method with Examples
- Java Guava | Shorts.contains() method with Examples
- Java Guava | Shorts.max() method with Examples
- Java Guava | Shorts.min() method with Examples
- Java Guava | Floats.contains() method with Examples
- Java Guava | Bytes.contains() method with Examples
- Java Guava | Longs.max() method with Examples
- Java Guava | Longs.contains() method with Examples
- Java Guava | Doubles.max() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.