Home »
Java programming language
Java - Character Class toString() Method
Character class toString() method: Here, we are going to learn about the toString() method of Character class with its syntax and example.
By Preeti Jain Last updated : March 17, 2024
Character class toString() method
- toString() method is available in java.lang package.
- toString() method is used to return the String object denoting the given Char value.
- toString() method does not throw an exception at the time of conversion an object to a string.
Syntax
public String toString(Char value);
Parameters
- Char value – represents the Char value to be converted.
Return Value
The return type of this method is String, it returns a string representation of the given Char value.
Example
// Java program to demonstrate the example
// of String toString(Char value) method of Character class
public class ToStringOfCharacter {
public static void main(String[] args) {
// It returns P
String result1 = Character.toString('P');
// It returns p
String result2 = Character.toString('p');
// Display values of result1 , result2
System.out.println("Character.toString('P'): " + result1);
System.out.println("Character.toString('p'): " + result2);
}
}
Output
Character.toString('P'): P
Character.toString('p'): p