How to Convert Char to String in Java? - GeeksforGeeks

02 Mar, 2022
If we have a char value like ‘G’ and we want to convert it into an equivalent String like “G” then we can do this by using any of the following four listed methods in Java:
Illustration:
Input  : 'G'
Output : "G"
Methods:
There are various methods by which we can convert the required character to string with the usage of wrapper classes and methods been provided in java classes.
Using concatenation of stringsUsing toString() method of Character classUsing Character wrapper classUsing valueOf() method of String class
Using concatenation of strings
Using toString() method of Character class
Using Character wrapper class
Using valueOf() method of String class
Let us discuss these methods in detail below as follows with clean java programs as follows:
Method 1: Using concatenation of strings 
We can convert a char to  a string  object in java by concatenating the given character with an empty string .
Example
Java
// Java Program to Convert Char to String// Using Concatenation in Strings // Importing the required packagesimport java.io.*;import java.util.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {         // Declaring a char variable        char c = 'G';         // Concatenating the char variable        // with an empty string        String s = "" + c;               // Print and display the above string        System.out.println(            "Char to String using Concatenation :"            + " " + s);    }}
  
Char to String using Concatenation : G
 
Method 2: Using toString() method of Character class 
 
We can convert a char to a string  object in java by using the  Character.toString() method.
 
Example
 
Java
// Java Program to Convert Char to String// Using toString() method of Character class // Importing the required packagesimport java.io.*;import java.util.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {         // Declaring a char variable        char c = 'G';         // Converting the char to String using toString        // method of Character class and storing it in a        // string        String s = Character.toString(c);         // Print and display the above string        System.out.println(            "Char to String using Character.toString method :"            + " " + s);    }}
  
Char to String using Character.toString method : G
 
Method 3: Using Character wrapper class
 
We can convert a char to  a string  object in java  by using java.lang.Character class, which is a wrapper for char primitive type.
 
Note: This method may arise a warning due to the new keyword as Character(char) in Character has been deprecated and marked for removal.
 
Example
 
Java
// Java Program to Convert Char to String// Using toString() method of Character class // Importing the required packagesimport java.io.*;import java.util.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {         // Declaring a char variable        char c = 'G';         // Converting the char to String using toString        // method of Character class and storing it in a        // string        String s = Character.toString(c);         // Print and display the above string        System.out.println(            "Char to String using Character.toString method :"            + " " + s);    }}
  
 
Method 4-A: Using String.valueOf() method of String class
 
We can convert a char to  a string  object in java  by using String.valueOf(char[]) method.
 
Example
 
Java
// Java Program to Convert Char to String// Using String.valueOf() method of String class // Importing the required packagesimport java.io.*;import java.util.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {         // Declaring a char variable        char c = 'G';         // Converting char to String by        // using String.valueOf() method        String s = String.valueOf(new char[] { c });         // Print and display the above-stored string        System.out.println(            "Char to String using String.valueOf(new char[]) method :"            + " " + s);    }}
  
Char to String using String.valueOf(new char[]) method : G
 
Method 4-B: Using valueOf() method of String class 
 
We can convert a char to  a string  object in java  by using String.valueOf() method.
 
Example
 
Java
// Java Program to Convert Char to String// Using valueOf() method of String class // Importing the required packagesimport java.io.*;import java.util.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {        // Declaring a char variable        char c = 'G';               // Converting char to String        // using String.valueOf() method        String s = String.valueOf(c);         // Print and display the String s        System.out.println(            "Char to String using String.valueOf() method :"            + " " + s);    }}
  
Char to String using String.valueOf() method : G
 
avtarkumar719
Java-String-Programs
Picked
TrueGeek-2021
Java
Java Programs
TrueGeek
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Constructors in Java
Stream In Java
Exceptions in Java
Different ways of Reading a text file in Java
Functional Interfaces in Java
Convert a String to Character array in Java
Java Programming Examples
Convert Double to Integer in Java
Implementing a Linked List in Java using Class
How to Iterate HashMap in Java?