The java.lang.Character.Subset class instances represent particular subsets of the Unicode character set. The only family of subsets defined in the Character class is UnicodeBlock.

Class Declaration

Following is the declaration for java.lang.Character.Subset class −

publicstaticclassCharacter.SubsetextendsObject

Class Constructors

Sr.No.Constructor & Description
1protected Character.Subset(String name)This constructs a new Subset instance.

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

Class Methods

Sr.No.Method & Description
1equals()This method compares two Subset objects for equality.
2hashCode()This method returns the standard hash code as defined by the Object.hashCode() method.
3toString()This method returns the name of this subset.

Comparing Subset objects for Equality Example

In the following example, we instantiate CharacterSubsetDemo class objects. The method Java Character.Subset equals() is then called on these objects to check whether they are equal or not.

Open Compiler

packagecom.tutorialspoint;publicclassCharacterSubsetDemoextendsCharacter.Subset{// constructor of super classCharacterSubsetDemo(String s){super(s);// invokes the immediate parent class: Object}publicstaticvoidmain(String[] args){CharacterSubsetDemo obj1 =newCharacterSubsetDemo("admin");CharacterSubsetDemo obj2 =newCharacterSubsetDemo("webmaster");CharacterSubsetDemo obj3 =newCharacterSubsetDemo("administrator");// compares Subset objects for equalityboolean retval = obj1.equals(obj1);System.out.println("Object obj1 is equal to obj1 ? "+ retval);
      retval = obj2.equals(obj1);System.out.println("Object obj1 is equal to obj2 ? "+ retval);
      retval = obj3.equals(obj1);System.out.println("Object obj1 is equal to obj3 ? "+ retval);}}

Output

Let us compile and run the above program, this will produce the following result −

Object obj1 is equal to obj1 ? true
Object obj1 is equal to obj2 ? false
Object obj1 is equal to obj3 ? false

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *