Java - Character.Subset Class toString() Method

Character.Subset class toString() method: Here, we are going to learn about the toString() method of Character.Subset class with its syntax and example. By Preeti Jain Last updated : March 17, 2024

Character.Subset class toString() method

  • toString() method is available in java.lang package.
  • toString() method is used to return the string representation of this Subset object or in other words, we can say it returns the name of this Subset.
  • toString() method is a non-static method, it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
  • toString() method is a final method it does not override in child class.
  • toString() method does not throw an exception at the time of conversion an object to a string.

Syntax

public final String toString();

Parameters

  • It does not accept any parameter.

Return Value

The return type of this method is String, it returns a string representation of this Subset object.

Example

// Java program to demonstrate the example 
// of String toString() method of 
// Character.Subset class

public class ToStringOfCharacterSubset extends Character.Subset {
    ToStringOfCharacterSubset(String str) {
        super(str);
    }

    public static void main(String[] args) {
        String str1 = new String("Java");
        ToStringOfCharacterSubset ob1 = new ToStringOfCharacterSubset(str1);

        String str2 = new String("Programming");
        ToStringOfCharacterSubset ob2 = new ToStringOfCharacterSubset(str2);

        String s1 = ob1.toString();
        System.out.println("ob1:" + ob1);
        System.out.println("ob1.toString(): " + s1);

        System.out.println();

        String s2 = ob2.toString();
        System.out.println("ob2:" + ob2);
        System.out.println("ob2.toString(): " + s2);
    }
}

Output

ob1:Java
ob1.toString(): Java

ob2:Programming
ob2.toString(): Programming

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.