Home » Java programming language

Java Character class equals() method with example

Character class equals() method: Here, we are going to learn about the equals() method of Character class with its syntax and example.
Submitted by Preeti Jain, on November 01, 2019

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);

Parameter(s):

  • 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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.