How to convert char to String in Java

In Java character can be converted to String using the methods mentioned below:

Converting a char to string using addition operator

A character can be converted to string using the addition operator. The addition operator is used to concatenate. The character is concatenated with the string and the result is a string.

char c = 'A';
String str = c + " Programmer";
System.out.println("String after conversion: " + str);

The output is

String after conversion: A Programmer

Converting char to string using String.valueOf() method

The String.valueOf() method of the String class can be used to convert a character to a string. This method accepts character as a parameter and returns the equivalent String.

char ch = 'Y';
// converting char to string
String str = String.valueOf(ch); 
System.out.println("String after conversion is: " + str);

The output is

String after conversion is: Y

Converting char to string using Character.toString() method

The Character.toString() method of the Character class can be used to convert a character to a string. This method accepts character as a parameter and returns the equivalent string.

char ch = 'B';
String str = Character.toString(ch);
System.out.println("String after conversion is: " + str);

The output is

String after conversion is: B
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions