java.lang.Character equals(Object obj)
Description
The equals(Object obj) java method compares this object against the specified object. The result is true if and only if the argument is not null and is a Character object that represents the same char value as this object.
Important Notes:
- This 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 Character class returns true if the objects are the same; false otherwise.
Compatibility
Requires Java 1.0 and up
Java Character equals(Object obj) Example
Below is a simple java example on the usage of equals(Object obj) method of Character class.
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * equals(Object obj) method of Character class. */ public class CharacterEqualsExample { public static void main(String[] args) { // instantiate a Character Character charValue = new Character('a'); // instantiate an Object Object obj = new Character('a'); // test equality of the two value if (charValue.equals(obj)) { System.out.println("they are equal using equals test"); } else { System.out.println("they are not equal using equals test"); } // test equality of the two value using == if (charValue == obj) { System.out.println("they are equal using == test"); } else { System.out.println("they are not equal using == test"); } } }
Sample Output
Below is the sample output when you run the above example.