Java Convert char to String with examples
In this tutorial, we will see how to convert a char to string with the help of examples.
There are two ways you can do char to String conversion –
1. Using String.valueOf(char ch) method
2. Using Character.toString(char ch) method
Java char to String example using String.valueOf(char ch)
We can use the valueOf(char ch) method of String class to convert a passed char ch to a String. This method accepts char as an argument and returns the string equivalent of the argument.
In the following example we have a char ch with the value ‘P’ and we are converting this to a String str using the String.valueOf() method. The value of the String after conversion is «P» .

Output:
Java char to String conversion using Character.toString(char ch)
We can also use the toString(char ch) method of Character class to convert the passed char ch to a String. Similar to String.valueOf(char ch) method, this method also accepts char as a parameter and returns an equivalent String.
In the following example we are converting a char to String using Character.toString(char ch) method.

Output:
Convert char to String in Java

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
Sometimes we have to convert char to String in java program. Here we will look into different methods you can convert character to string in java. We will also learn how to convert char array to String using different methods.
Convert char to String Java
Here is a simple program showing different ways to convert char to string in java.
Let’s look at these methods one by one.
String.valueOf(char c)
This is the most efficient method to convert char to string. You should always use this method and this is the recommended way to convert character to string in java program.
Character.toString©
This method internally calls String.valueOf(c) , so there is no difference between this one. You can use this too if you are already using Character class in your code.
new Character©.toString();
This is another way, however not recommended because we are creating a Character unnecessarily.
String concatenation
str = "" + c; is the worst way to convert char to string because internally it’s done by new StringBuilder().append("").append(c).toString() that is slow in performance. Let’s look at the two methods to convert char array to string in java program.
String constructor
You can use String(char[] value) constructor to convert char array to string. This is the recommended way.
String.valueOf(char[] data)
String valueOf method is overloaded and there is one that accepts character array. Internally this method calls the String constructor, so it’s same as above method. That’s all for converting char to string and char array to string in java.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
6 ways to convert char to String in Java — Examples
If you have a char value like ‘a’ and you want to convert it into equivalent String like «a» then you can use any of the following 6 methods to convert a primitive char value into String in Java :
1) String concatenation
2) String.valueOf()
3) Character.toString()
4) Character wrapper class + toString
5) String constructor with a char array
6) String.valueOf(char [])
In this article, we will see examples of each approach and learn a little bit more about it. Actually, there is a lot of overlap between each method as some of them internally call String.valueOf() , which eventually calls to a String constructor which accepts char array and creates a String object containing primitive char value with length 1. Once you know, how they work internally, it easy to decide which one is more efficient for the purpose.
1.Char to String using concatenation in Java
This is the easiest way to convert a char to a String object in Java. All you need to do is concatenate a given character with an empty String, as shown in the following example:
Remark: This is the simplest method to convert a char value to a String but it’s less efficient and takes more memory than required. Compile translate String concatenation into the following code:
This is less efficient because the StringBuilder is backed by a char[] of size 16, which is a waste of memory if you just converting one character. This array is then defensively copied by the resulting String
2. Character to String using String.valueOf()
This is the standard way to convert a char primitive type into a String object. If you remember, we have already used the valueOf() method to convert String to int and String to double in Java. Here is the example of using this method to convert char to String:
Remark: String.valueOf(char) is the most efficient method for converting char to String in Java because it just uses a character array of size one to wrap a given character and pass it to String constructor, as shown below (from JDK) :
3. Char to String conversion with Character.toString()
This is the third example to convert a char primitive value to a String object in Java. In this example, we have used Character.toString() method.
Remark: This method returns a String object representing the given char. It returns a String of length one consisting solely of the specified char. Internally it also calls String.valueOf(char c) method.
Anyway, here is a nice summary of all the six ways to convert a char value to a String object in Java:

4. Char to String using a Character wrapper class
This is the 4th example of converting a char value to a String object in Java. This time, we will use java.lang.Character class, which is a wrapper for char primitive type.
Remark: This method returns the String equivalent of the Character object’s value of length 1. Internally this method wraps the encapsulated char value into a char array and passed it to the String.valueOf(char[]) method.
String constructor with a char array
Here is one more way to convert a char value to a String object in Java. In this example, we have wrapped the single character into a character array and passed it to a String constructor which accepts a char array as shown below:
Remark: This is the method which is internally called by String.valueOf() method for char to String conversion. This constructor allocates a new String object to represent a sequence of characters passed via char array argument. The contents of the character array are defensively copied so that subsequent modification of the character array doesn’t affect the newly created String.
char to String using String.valueOf(char[])
This the sixth and last way to perform char to String conversion in our article, here is the sample code:
4 Methods To Convert Char To String In Java
In this tutorial, we will cover the various ways of converting Java primitive data type char values to data type String.
We will be learning the following methods in Java for char to String conversion:
- String.valueOf()
- Character.toString(char c )
- Character class toString()
- String concatenation
What You Will Learn:
Convert Char To String In Java
Java char is a primitive data type, char data type variable holds only a single character. For Example, alphabets like ‘a’, ‘A’, or numbers like ‘1’, ‘2’ etc., and also special characters like ‘@’, ‘!’ etc.
In some scenarios, this data needs to be converted to Java String class type. A String class is not a Java primitive data type.
For example, in the Java program, the input value coming is of primitive data type ‘char’. But this value is needed for further processing or decision-making using String methods. In such cases, char is first converted to String data type as a pre-requisite.
Let’s have a look at the different ways of converting Java primitive data type of char to String data type. We will see each method in detail.
#1) Using String Class valueOf() Method
Let’s have a look at the method signature of the String class’ valueOf () method. This is a static overloading method of String class that is used to convert arguments of primitive data types like char, float, etc. to String data type.
public static String valueOf(char ch)
This static method of String class receives an argument of primitive data type char and returns the string representation of char argument.
Parameters:
ch: This is a char data type value.
Returns:
The is char argument’s string representation.
Let’s understand how to use the valueOf() method to convert char to String with the help of the following sample program.
In this program, we are performing the following tasks:
- Value of variable customerGender data type char is converted to String type using the String.valueOf() method and,
- The String value of variable gender is used in an if-then statement further to print the appropriate message for the gender on the console.
Here is the sample program:
Here is the program Output:
Welcome to WearToShine – Online shopping store for apparel
gender —>F
Welcome Madam, click on ‘Women’s apparel’ link to check our trendy collection of new arrivals : Skirts, Tops , partywears and More
In the above program, we can see the following char variable value:
Convert char to String using String.valueOf() method as shown below:
This value of gender variable is used in the if-else condition and prints an appropriate message on the console for gender “F” i.e. female as follows:
#2) Using Character.toString(char ch) Static Method
The Character class has a static method of toString(). This method returns a value of data type int represented by a specified Unicode character.
Here is the method signature of the toString (char ch) method for char data type:
public String toString(char ch)
This static method returns an object of String that represents this character’s value. The result string has length 1 of the specified char.
ch – This is the char that needs to be converted
Returns:
This is a string representation of the object.
Let’s understand the use of this Character.toString(char ch) method to convert the character to the String value.
Let us have a look at the following sample program where we are performing the following task:
- char data type value is assigned to the ‘resultStatus’ variable. This char value is converted to String using Character.toString(char ch) method and,
- The string variable ‘result’ value is used in the equals condition further in an if-else statement and prints an appropriate result message on the console.
Here is the program Output:
Congratulations !! You have successfully cleared the exam.
In the above program, we are converting char variable resultStatus value to String value and assigning it to variable result.
This String value is further used in if (result.equalsIgnoreCase(“P”)) condition and the following statement gets executed:
Thus, we see a message on the console as below:
#3) Using Character Class toString() Method
This is an instance method of Character class which also returns a value of data type String represented by a specified Unicode character.
Here is the method signature of the toString () method:
public String toString()
This method returns an object of String that represents this character’s value. The result string has length 1 which is the value of data type char represented by Character object.
Returns:
This is a string representation of the object.
Let’s understand the use of this toString() method to convert a character to a String value.
Let us have a look at the following sample program where the value needs to be converted to upper case. For that char data type value needs to be first converted to a String value.
In this program we are performing the following tasks:
- Create an instance of Character class.
- Convert this Character instance to String using the toString() method.
- Further, this String value is used for further manipulation i.e. converting to upper case using String method toUpperCase().
Here is the program Output:
String in upper case —>A
So, in the above program, we are converting char variable value ‘a’ to Character value.
We are first creating an instance of the Character class using Character() constructor.
Now, invoke toString() method on Character instance sampleChar which converts it to String:
This sampleChar string can be used further in the program for String manipulation method like toUpperCase():
#4) Using String Concatenation
This is the simplest but less efficient way of converting char data type value to String class value. In this way, the char data type value is concatenated with the String.
Let us understand this with the following sample program.
Here is the program Output:
In the above sample code, we have concatenated char x with String “ “ to convert it to a String value.
With this, we have covered all the ways of converting Java char to String. Now, let us have a look at the frequently asked questions.
Q #1) Can you add char to string Java?
Answer: In Java, you can append char to String by concatenating char value with String.
For Example,
Q #2) Can a char be a string?
Answer: The char can be converted to String class value using the below Java class methods:
- String.valueOf()
- Character.toString(char c )
- Character class toString()
- String concatenation
Q #3) What is the difference between char and string?
Answer: char is Java’s primitive data type. It holds a single character which could be a letter, number, or a special character. char data type variable is assigned a single character value enclosed with a single quote ‘ ’.
For Example,
char x = ‘a’;
Char x = ‘1’;
Char x = ‘@’;
Whereas String is a Java class. String class is used by creating an instance of it or assigning value to it. It holds a multiple numbers of characters. String class variable is assigned a sequence of characters enclosed within double quotes “ ”.
For Example,
String x = “abc”;
String x = “1234”;
String x = “1@3a”;
Conclusion
In this tutorial, we have seen the below ways of converting Java primitive data type char values to Java String class values:
- String.valueOf()
- Character.toString(char c )
- Character class toString()
- String concatenation
We have covered each of these ways in detail and explained the use of each method with the help of a sample Java program.