Java Data Type Tutorial - Byte compare(byte x, byte y) example








Byte compare(byte x, byte y) compares two byte values.

Syntax

compare has the following syntax.

public static int compare(byte x, byte y)

Parameters

compare has the following parameters.

x
the first byte to compare
y
the second byte to compare

Return

compare returns

  • 0 if x == y;
  • a value less than 0 if x < y;
  • a value greater than 0 if x > y




Example

In the following code shows how to use Byte.compare(byte x, byte y) method.

public class Main {

   public static void main(String[] args) {
     byte b1 = 1;
     byte b2 = 2;
     System.out.println(  Byte.compare(b1,b2));
   }
}

The code above generates the following result.