Java convert char to string using Character.toString() method
package com.w3spoint;
public class CharToString {
public static void main(String args[]){
char ch = 'a';
//Convert char to string
String str = Character.toString(ch);
System.out.println("String is: "+str);
}
} |
package com.w3spoint; public class CharToString {
public static void main(String args[]){
char ch = 'a';
//Convert char to string
String str = Character.toString(ch);
System.out.println("String is: "+str);
}
}
Output:
Download this example.
Java convert char to string using String.valueOf() method
package com.w3spoint;
public class CharToString {
public static void main(String args[]){
char ch = 'a';
//Convert char to string
String str = String.valueOf(ch);
System.out.println("String is: "+str);
}
} |
package com.w3spoint; public class CharToString {
public static void main(String args[]){
char ch = 'a';
//Convert char to string
String str = String.valueOf(ch);
System.out.println("String is: "+str);
}
}
Output:
Download this example.