The equals() method of Short class is a built in method in Java which is used to compare the equality given Object with the instance of Short invoking the equals() method.
Syntax
ShortObject.equals(Object a)
Parameters: It takes an Object type object a as input which is to be compared with the instance of the Short 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 ShortObject.
Below is the implementation of equals() method in Java:
Example 1:
class GFG {
public static void main(String[] args)
{
Short a = new Short( "20" );
Short b = new Short( "20" );
boolean output = a.equals(b);
System.out.println( "Does " + a
+ " equals " + b
+ " : " + output);
}
}
|
Output:
Does 20 equals 20 : true
Example 2:
class GFG {
public static void main(String[] args)
{
Short a = new Short( "2" );
Short b = new Short( "20" );
boolean output = a.equals(b);
System.out.println( "Does " + a
+ " equals " + b
+ " : " + output);
}
}
|
Output:
Does 2 equals 20 : false
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Dec, 2018
Like Article
Save Article