Compare two Byte objects.
The compareTo method of Byte class is used for comparing two Byte objects.
public class ByteWrapper {
public static void main(String[] args) {
Byte b1 = new Byte("10");
Byte b2 = new Byte("10");
int comparedValue = b1.compareTo(b2);
System.out.println(comparedValue);
if (comparedValue == 0){
System.out.println("Both objects are equal");
}
else if (comparedValue > 0){
System.out.println("First object is greater than second object.");
}
else if(comparedValue <0){
System.out.println("First object is less than second object.");
}
}
}
Tags: Byte, Byte examples, Byte wrapper class, java.lang, java.lang.Byte
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply