How to convert Char to String in Java
In this section, we will show you how to convert Char to String in Java.
Main.java
public class Main {
public static void main(String[] args) {
String str = "knowledgefactory.net";
//convert a String into char
char charK = str.charAt(0); //k
char charL = str.charAt(4);//l
char charC = str.charAt(11);//c
System.out.println(charK);
System.out.println(charL);
System.out.println(charC);
//convert char back to String
String temp = Character.toString(charK);
System.out.println(temp);
}
}
Console Output:
k
l
c
k