Home » Java Byte compareTo() Method

Java Byte compareTo() Method

by Online Tutorials Library

Java Byte compareTo() method

The compareTo() method of Java Byte class compares two Byte objects numerically

Syntax:

Parameters:

The parameter ‘anotherByte’ represents the Byte to be compared.

Specified by

This method is specified by compareTo in interface Comparable<Byte>

Return Value

This method returns an integer value.

  • It returns zero, if this Byte is equal to the parameter.
  • It returns positive one, if this Byte is numerically greater than the argument Byte.
  • It returns negative one, if this Byte is numerically smaller than the argument Byte.

Example 1

Test it Now

Output:

127 is greater than 67 .  

Example 2

Output:

Enter your age : 24  Congratulations! You are an adult. Now you can vote.  

Example 3

Test it Now

Output:

Error:(5, 18) java: incompatible types: int cannot be converted to java.lang.Byte  

Next TopicJava Byte

You may also like