Java Character toString(int codePoint) Method

Java toString(int codePoint) method is a part of the Character class. This method returns the equivalent String object of the specified Unicode code point character value. The result is a string of length 1 consisting solely of the specified char.This method also handles supplementary characters.

This method is compatible with Java 11 or more and used to convert char value into String.

Syntax:

public static String toString(int codePoint) 

Parameters:

The parameter passed is the Unicode code point character value whose equivalent String is to be returned.

Returns:

Returns the String equivalent of the code point character passed as a parameter.

Example 1:

Here, the character values are converted into its equivalent String representations.

public class StudyTonight
{  
    public static void main(String[] args)
    {  
        int cp1 = 88;
        int cp2 = 100;
        System.out.println("Equivalent String is : "+Character.toString(cp1));   
        System.out.println("Equivalent String is : "+Character.toString(cp2));   
    }  
}


Equivalent String is : X
Equivalent String is : d

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner;  
public class StudyTonight
{  
    public static void main(String[] args) 
    {  
        try
        {
            System.out.print("Enter the value ");  
            Scanner sc = new Scanner(System.in);  
            int cp = sc.nextInt();  
            String s = Character.toString(cp); //converting to string
            System.out.println("String value is : "+ s);          
        }
        catch(Exception e)
        {
            System.out.println("Invalid input!!");
        }
    }  
}  


Enter the value 85
String value is : U
*************************
Enter the value 102
String value is : f