java.lang.Long equals(Object obj)
Description
The equals() java method compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object.
Notes:
- This method is overrides equals in class Object
Method Syntax
public boolean equals(Object obj)
Method Argument
| Data Type | Parameter | Description |
|---|---|---|
| N/A | N/A | N/A |
Method Returns
The equals(Object obj) method of Long class returns true if the objects are the same; false otherwise.
Compatibility
Requires Java 1.0 and up
Java Long equals() Example
Below is a simple java example on the usage of equals() method of Long class.
package com.javatutorialhq.java.examples;
/*
* This example source code demonstrates the use of
* equals(Object obj) method of Long class
*/
public class LongEqualsExample {
public static void main(String[] args) {
// initialize a new Long object
Long l = 321L;
// initialize an object
Object obj = new Long(321L);
// check equality
boolean result = l.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
*/
}
}
Sample Output
Below is the sample output when you run the above example.
