Home »
Java programming language
Java - Character Class equals() Method
Character class equals() method: Here, we are going to learn about the equals() method of Character class with its syntax and example.
By Preeti Jain Last updated : March 17, 2024
Character class equals() method
- equals() method is available in java.lang package.
- equals() method is used to check equality or inequality of this Subset Object against the given Subset Object or in other words we can say this method is used to compare two Subset objects.
- equals() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- equals() method is a final method it does not override in child class.
- equals() method does not throw an exception at the time of comparing two Subset Objects.
Syntax
public final boolean equals(Object value2);
Parameters
- Object value2 – represents the Object to compare with.
Return Value
The return type of this method is boolean, it returns a boolean value based on the following value,
- It returns true, if Object1 is same as Object2.
- It returns false, if Object1 is not same as Object2.
Example
// Java program to demonstrate the example
// of boolean equals(Object value) method of
// Character.Subset class
public class EqualsOfCharacterSubset extends Character.Subset {
EqualsOfCharacterSubset(String str) {
super(str);
}
public static void main(String[] args) {
String str1 = new String("Java");
EqualsOfCharacterSubset value1 = new EqualsOfCharacterSubset(str1);
String str2 = new String("Programming");
EqualsOfCharacterSubset value2 = new EqualsOfCharacterSubset(str2);
boolean res = value1.equals(value2);
// Check equality of Character.Subset objects
if (res)
System.out.println("value1.equals(value2): " + res);
else
System.out.println("value1.equals(value2): " + res);
}
}
Output
value1.equals(value2): false