Java source code examples

Java source code samples. Java code examples.

Compare two Byte objects.

* * * * * 1 votes

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.");
		}

	}
}
  • Share/Bookmark

Tags: java.lang

Discuss This Code