Java Convert Character to String Example

In this article, we will show you how to convert Java wrapper class Character or primitive type char to String code examples. There are different ways we can convert Java wrapper class Character or primitive type char to String.
In this example, we will demonstrate converting wrapper class Character or primitive type char to String in 2 ways.
  • Convert using String.valueOf(b)
  • Convert using Character.toString(b)
Refer the comments in below program self-descriptive.

/**
 * Program to convert char to string
 * @author javaguides.net
 *
 */
public class ConvertCharacterToStringExample {
 public static void main(String[] args) {
  /* Method 1: using valueOf() method
      * of String class.
      */
  char c = 'a';
  String charStr = String.valueOf(c);
  System.out.println("Convert char to string using valueOf method ::" + charStr);
  
  
  /* Method 2: using toString() method 
      * of Character class
      */
  String charStr1 = Character.toString(c);
  System.out.println("Convert char to string using Character.toString method ::" + charStr1);
 }
}
Output:
Convert char to string using valueOf method ::a
Convert char to string using Character.toString method ::a

Related Java String Conversion Examples

Comments