Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes

The java.lang.Byte.equals() method is used to compare this object to the specified object. The result is true if and only if the argument is not null and is a Byte object that contains the same byte value as this object.


public boolean equals(Object obj)


obj Specify the object to compare with.

Return Value

Returns true if the objects are the same; false otherwise.




In the below example, the java.lang.Byte.equals() method is used to compare given Byte objects for equality.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating Byte objects
    Byte val1 = new Byte("5");
    Byte val2 = new Byte("5");
    Byte val3 = new Byte("-5");

    //checking Byte objects for equality
    System.out.println("Is val1 == val2?: " + val1.equals(val2)); 
    System.out.println("Is val1 == val3?: " + val1.equals(val3));    

The output of the above code will be:

Is val1 == val2?: true
Is val1 == val3?: false

❮ Java.lang - Byte