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:
// 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); } } |
Does 20 equals 20 : true
Example 2:
// 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); } } |
Does 2 equals 20 : false
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java Guava | Shorts.indexOf(short[] array, short target) method with Examples
- Java Guava | Shorts.indexOf(short[] array, short[] target) method with Examples
- Java.lang.Short toString() method in Java with Examples
- Short compareTo() method in Java with Examples
- Short doubleValue() method in Java with Examples
- Short hashCode() method in Java with Examples
- Java Guava | compare() method of Short Class with Examples
- ShortBuffer put(int, short) method in Java With Examples
- Java.util.Arrays.equals() in Java with Examples
- Java Long equals() method with Examples
- Character.equals() method in Java with examples
- Double.equals() Method in Java with Examples
- EnumMap equals() Method in Java with Examples
- Java 8 Clock equals() Method with Examples
- FloatBuffer equals() method in Java with Examples
- ShortBuffer equals() method in Java with Examples
- DoubleBuffer equals() method in Java with Examples
- ByteBuffer equals() method in Java with Examples
- Boolean equals() method in Java with examples
- Byte equals() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

