converting char to string in java code example
Example 1: convert char to string java
char c = 'a';
String s = Character.toString(c);
//s == "a"
Example 2: convert char[] to string
char[] chars = {'a','b','c','d','e'};
string s = new string(chars);
Example 3: how to change char to string
from character to string:
char c = 'a';
String s = Character.toString(c);
//s == "a"
Example 4: Converting Char to String in java
class CharToStringDemo
{
public static void main(String args[])
{
// Method 1: Using toString() method
char ch = 'a';
String str = Character.toString(ch);
System.out.println("String is: "+str);
// Method 2: Using valueOf() method
String str2 = String.valueOf(ch);
System.out.println("String is: "+str2);
}
}