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

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete