Last Updated : 11 Jul, 2025
The
equals()method of
Short classis a built in method in Java which is used to compare the equality given Object with the instance of Short invoking the
equals()method.
SyntaxShortObject.equals(Object a)Parameters:
It takes an Object type object
aas input which is to be compared with the instance of the Short object calling the
equalsmethod.
Return Value:It return an
booleanvalue. It returns true if the value of 'a' is equal to the value of ShortObject. Below is the implementation of equals() method in Java:
Example 1: Java
// Java code to demonstrate
// Short equals() method
class GFG {
public static void main(String[] args)
{
// creating a Short object
Short a = new Short("20");
// creating a Short object
Short b = new Short("20");
// equals method in Short class
boolean output = a.equals(b);
// Printing the output
System.out.println("Does " + a
+ " equals " + b
+ " : " + output);
}
}
Output:
Does 20 equals 20 : trueExample 2: Java
// Java code to demonstrate
// Short equals() method
class GFG {
public static void main(String[] args)
{
// creating a Short object
Short a = new Short("2");
// creating a Short object
Short b = new Short("20");
// equals method in Short class
boolean output = a.equals(b);
// Printing the output
System.out.println("Does " + a
+ " equals " + b
+ " : " + output);
}
}
Output:
Does 2 equals 20 : false
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4