The compare() method of Byte class is a built in method in Java which is used to compare two byte values.
Byte.compare(byte a, byte b)
Parameters: It takes two byte value ‘a’ and ‘b’ as input in the parameters which are to be compared.
Return Value: It returns an int value. It returns:
- 0 if ‘a is equal to ‘b,
- a positive value ‘a’ is greater than ‘b’,
- a negative value ‘b’ is greater than ‘a’
Below is the implementation of compare() method in Java:
Comparing 20 and 20 : 0
Comparing 20 and 10 : 10
Comparing 10 and 20 : -10
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.