Convert character value to String in Java

static String valueOf(char b) method of String class can be used to convert a character value to String in Java.

For eg. when we pass a character value 'a' to valueOf method, it returns a string value 'a'.


Example 1

class CtoSTest{

public static void main(String args[]){

char c='s';

String ctoSt=String.valueOf(c);

System.out.println(ctoSt);

}

}

Output 1

s


Example 2

class CtoSTest{

public static void main(String args[]){

char ch='a';

String ctoSt=String.valueOf(ch);

System.out.println(ctoSt);

}

}

Output 2

a