This post will discuss how to convert a char to a String in Java.

Converting a char to its equivalent string is very simple and straightforward in Java. We can use any of the following methods to convert a char to a string in Java:

1. Using String.valueOf() method

The standard approach to convert a char to a string in Java is to use the String.valueOf(char) method, which returns the string representation of the specified char argument. This is the most efficient method for converting a char to a string. Here’s an example:

Download  Run Code

 
This method basically wraps the specified char in a single-element character array and passes it to the String constructor, as evident from the following snippet. It also overloaded for other primitive types.

2. Using Character.toString() method

We can also use the Character.toString() method, which returns a String object representing the specified char value. It is equivalent to calling the String.valueOf() method. Here’s an example:

Download  Run Code

 
This method internally calls the String.valueOf() method, as evident from the following snippet.

3. String Concatenation

Another option is to use the concatenation operator (+) to append a char variable to an empty string literal, which will convert the char value to a string object. Here’s an example:

Download  Run Code

 
This looks like a pretty simple approach, but this is the least efficient method because the string concatenation creates a StringBuilder object, and appends the char and the String to it, then calls its toString() method. For example, the above code compiles down to something like:

Download  Run Code

4. Using String Constructor

We have seen that String.valueOf() uses a single-element character array to wrap the specified character and then pass it to the String constructor. We can directly call the String constructor that takes a char array as an argument. This creates a new String object with the contents of the char array. Here’s an example:

Download  Run Code

5. Using String.format() method

Finally, we can use the String.format() method that returns a formatted string using the given format string and arguments. For example, we can use the following code to convert a char to a String. Here, the format string "%c" specifies that the argument should be formatted as a character.

Download  Run Code

That’s all about converting a char to a String in Java.