Java Data Type Tutorial - Byte equals(Object obj) example








Byte equals(Object obj) compares this object to the specified object.

The result is true if the argument is not null and is a Byte object that contains the same byte value as this object.

Syntax

equals has the following syntax.

public boolean equals(Object obj)

Overrides

equals in class Object

Parameters

equals has the following parameters.

obj
the object to compare with

Return

equals returns true if the objects are the same; false otherwise.





Example

In the following code shows how to use Byte.equals(Object obj) method.

public class Main {
  public static void main(String[] args) {
    
    Byte byte1 = new Byte("1");
    Byte byte2 = new Byte("2");
    System.out.println(byte1.equals(byte2));
  }
}

The output: