Convert char to String in Java
In this tutorial, I will show you all how to convert char to String in Java. Let consider the following example:
1 2 3 4 5 6 7 8 9 |
package com.huongdanjava.javaexample; public class Example { public static void main(String[] args) { char c = 'K'; } } |
To convert this character “K” to String, we will use the Character object with method toString() as below:
1 2 3 4 5 6 7 8 9 10 11 12 |
package com.huongdanjava.javaexample; public class Example { public static void main(String[] args) { char c = 'K'; String s = Character.toString(c); System.out.println(s); } } |
Result: