java.lang.Short equals(Object obj)
Description
The equals(Object obj) method of Short class compares this object to the specified object. The result is true if and only if the argument is not null and is a Short object that contains the same short value as this object.
Notes:
- Overrides equals in class Object.
Method Syntax
public boolean equals(Object obj)
Method Argument
Data Type | Parameter | Description |
---|---|---|
Object | obj | the object to compare with |
Method Returns
The equals(Object obj) method of Short class returns true if the objects are the same; false otherwise.
Compatibility
Requires Java 1.1 and up
Java Short equals(Object obj) Example
Below is a simple java example on the usage of equals(Object obj) method of Short class.
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * equals(Object obj) method of Short class */ public class ShortEqualsExample { public static void main(String[] args) { // initialize a new Long object Short value = 132; // initialize an object Object obj = value; // check equality boolean result = value.equals(obj); // print result if (result) { System.out.println("They are equal"); } else { System.out.println("They are not equal"); } /* * This is a standard method inherited by all classes to class Object */ } }