Home » Java programming language

Java Character class toString() method with example

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

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

Parameter(s):

  • 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





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.