Convert a Char to a String in Java

  1. String.valueOf() to Convert Char to String in Java
  2. Character.toString() to Convert Char to String in Java
  3. String Concatenation to Convert Char to String in Java

This tutorial discusses three methods to convert a char to a string in Java.

String.valueOf() to Convert Char to String in Java

The most efficient way is to use the built-in function of the String class - String.valueOf(ch).

The below example illustrates this:

public class MyClass {
    public static void main(String args[]) {
      char myChar = 'c';
      String charToString = String.valueOf(myChar);
      System.out.println(charToString);
    }
}

Output:

> c

Character.toString() to Convert Char to String in Java

We can also use the built-in method of Character class to convert a character to a String.

The below example illustrates this:

public class MyClass {
    public static void main(String args[]) {
      char myChar = 'c';
      String charToString = Character.toString(myChar);
      System.out.println(charToString);
    }
}

Output:

> c

String Concatenation to Convert Char to String in Java

This method simply concatenates the given character with an empty string to convert it to a String.

The below example illustrates this.

public class MyClass {
    public static void main(String args[]) {
      char myChar = 'c';
      String charToString = myChar + "";
      System.out.println(charToString);
    }
}

Output:

> c

However, this is the least efficient method of all since the seemingly simple concatenation operation expands to new StringBuilder().append(x).append("").toString(); which is more time consuming than the other methods we discussed.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Java String

  • Replace Character in String in Java
  • Add Char to String in Java
  • Related Article - Java Char

  • Convert a String to Char in Java
  • Convert Binary String to Int in Java