Byte compare() method in Java with examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The compare() method of Byte class is a built in method in Java which is used to compare two byte values. Syntax 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: Example 1: Java // Java code to demonstrate // Byte compare() method class GFG { public static void main(String[] args) { // byte value 'a' byte a = 20; // byte value 'b' byte b = 20; // compare method of Byte class int output = Byte.compare(a, b); // printing the output System.out.println("Comparing " + a + " and " + b + " : " + output); } } Output: Comparing 20 and 20 : 0 Example 2: Java // Java code to demonstrate // Byte compare() method class GFG { public static void main(String[] args) { // byte value 'a' byte a = 20; // byte value 'b' byte b = 10; // compare method of Byte class int output = Byte.compare(a, b); // printing the output System.out.println("Comparing " + a + " and " + b + " : " + output); } } Output: Comparing 20 and 10 : 10 Example 3: Java // Java code to demonstrate // Byte compare() method class GFG { public static void main(String[] args) { // byte value 'a' byte a = 10; // byte value 'b' byte b = 20; // compare method of Byte class int output = Byte.compare(a, b); // printing the output System.out.println("Comparing " + a + " and " + b + " : " + output); } } Output: Comparing 10 and 20 : -10 Comment More infoAdvertise with us Next Article Byte equals() method in Java with examples S ShivamKD Follow Improve Article Tags : Java Java - util package Java-Functions Java-Byte java-lang-reflect-package +1 More Practice Tags : Java Similar Reads Byte compareTo() method in Java with examples The compareTo() method of Byte class is a built in method in Java which is used to compare the given Byte type object with the instance of Byte invoking the compareTo() method. Syntax ByteObject.compareTo(Byte a) Parameters: It takes a Byte type object a as input which is to be compared with the ins 2 min read Byte compareTo() method in Java with examples The compareTo() method of Byte class is a built in method in Java which is used to compare the given Byte type object with the instance of Byte invoking the compareTo() method. Syntax ByteObject.compareTo(Byte a) Parameters: It takes a Byte type object a as input which is to be compared with the ins 2 min read Byte byteValue() method in Java with examples The byteValue method of Byte class is a built in method in Java which is used to return the value of this Byte object as byte. Syntax ByteObject.byteValue() Return Value: It returns the value of ByteObject as byte. Below is the implementation of byteValue() method in Java: Example 1: Java // Java co 2 min read Byte byteValue() method in Java with examples The byteValue method of Byte class is a built in method in Java which is used to return the value of this Byte object as byte. Syntax ByteObject.byteValue() Return Value: It returns the value of ByteObject as byte. Below is the implementation of byteValue() method in Java: Example 1: Java // Java co 2 min read Byte equals() method in Java with examples The equals() method of Byte class is a built in method in Java which is used to compare the equality given Object with the instance of Byte invoking the equals() method. Syntax ByteObject.equals(Object a) Parameters: It takes an Object type object a as input which is to be compared with the instance 2 min read Byte equals() method in Java with examples The equals() method of Byte class is a built in method in Java which is used to compare the equality given Object with the instance of Byte invoking the equals() method. Syntax ByteObject.equals(Object a) Parameters: It takes an Object type object a as input which is to be compared with the instance 2 min read Like