Conversions
Java Program to Convert Char to String
A Java program to convert a Char to a String.
Problem Description
Write a Java program to convert a Char to a String.
Code
public class CharToString {
public static void main(String[] args) {
char c = 'S';
String s = String.valueOf(c);
String s2 = Character.toString(c);
System.out.println("String is: " + s);
System.out.println("String is: " + s2);
}
}Output
String is: S
String is: SExplanation
String.valueOf(char): Returns string representation of the char argument.Character.toString(char): Returns a String object representing the specified char.
