Wednesday, June 10, 2026
HomeLanguagesJavaByte equals() method in Java with examples

Byte equals() method in Java with examples

The equals() method of Byte class is a built in method in Java which is used to compare the equality given Object with the instance of Byte invoking the equals() method.

Syntax

ByteObject.equals(Object a)

Parameters: It takes an Object type object a as input which is to be compared with the instance of the Byte object calling the equals method.

Return Value: It return an boolean value. It returns true if the value of ‘a’ is equal to the value of ByteObject.

Below is the implementation of equals() method in Java:

Example 1:




// Java code to demonstrate
// Byte equals() method
  
class GFG {
    public static void main(String[] args)
    {
  
        // creating a Byte object
        Byte a = new Byte("20");
  
        // creating a Byte object
        Byte b = new Byte("20");
  
        // equals method in Byte class
        boolean output = a.equals(b);
  
        // Printing the output
        System.out.println("Does " + a + " equals "
                           + b + " : " + output);
    }
}


Output:

Does 20 equals 20 : true

Example 2:




// Java code to demonstrate
// Byte equals() method
  
class GFG {
    public static void main(String[] args)
    {
  
        // creating a Byte object
        Byte a = new Byte("2");
  
        // creating a Byte object
        Byte b = new Byte("20");
  
        // equals method in Byte class
        boolean output = a.equals(b);
  
        // Printing the output
        System.out.println("Does " + a + " equals "
                           + b + " : " + output);
    }
}


Output:

Does 2 equals 20 : false
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS