Java.lang.Character.equals() Method
Advertisements
Description
The java.lang.Character.equals(Object obj) 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.
Declaration
Following is the declaration for java.lang.Character.equals() method
public boolean equals(Object obj)
Overrides
equals in class Object
Parameters
obj - the object to compare with
Return Value
This method returns true if the objects are the same, false otherwise.
Exception
NA
Example
The following example shows the usage of lang.Character.equals() method.
package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
// create 2 Character objects c1, c2
Character c1, c2;
// create a boolean primitive res
boolean res;
// assign values to c1, c2
c1 = new Character('a');
c2 = new Character('A');
// assign the result of equals method on c1, c2 to res
res = c1.equals(c2);
String str = c1+ " and " + c2 + " are equal is " + res;
// print res value
System.out.println( str );
}
}
Let us compile and run the above program, this will produce the following result:
a and A are equal is false