Java Character.Subset Class



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 −

public static class Character.Subset
   extends Object

Class Constructors

Sr.No.

Constructor & Description

1

protected Character.Subset(String name)

This constructs a new Subset instance.

Class Methods

Sr.No.

Method & Description

1

equals()

This method compares two Subset objects for equality.

2

hashCode()

This method returns the standard hash code as defined by the Object.hashCode() method.

3

toString()

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.

package com.tutorialspoint;

public class CharacterSubsetDemo extends Character.Subset {
  
   // constructor of super class
   CharacterSubsetDemo(String s) {
      super(s); // invokes the immediate parent class: Object
   }
   public static void main(String[] args) {
      CharacterSubsetDemo obj1 = new CharacterSubsetDemo("admin");
      CharacterSubsetDemo obj2 = new CharacterSubsetDemo("webmaster");
      CharacterSubsetDemo obj3 = new CharacterSubsetDemo("administrator");

      // compares Subset objects for equality
      boolean 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
Advertisements