Javatpoint Logo
Javatpoint Logo

Java Byte compareTo() method

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



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


127 is greater than 67 .

Example 2


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

Example 3

Test it Now


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

Next TopicJava Byte

Youtube For Videos Join Our Youtube Channel: Join Now


  • Send your Feedback to

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA