Java char to String Example: Using Concatenation of Strings
We can convert a char to a string object in Java by concatenating the given character with an empty String.
Below is the java implementation of the above appraoch:
Java
// Java Program to Convert Char to String // Using Concatenation in Strings // Importing the required packages import java.io.*; import java.util.*; // Main class class GFG { // Main driver method public static void main(String[] args) { // Declaring a char variable char c = 'G' ; // Concatenating the char variable // with an empty string String s = "" + c; // Print and display the above string System.out.println( "Char to String using Concatenation :" + " " + s); } } |
Output
Char to String using Concatenation : G
How to Convert Char to String in Java?
In this article, we will learn how to Convert Char to String in Java. If we have a char value like âGâ and we want to convert it into an equivalent String like âGâ then we can do this by using any of the following three listed methods in Java.
- Using toString() method of Character class
- Using valueOf() method of the String class
- Using concatenation of strings
Example of Conversion of Char to String Java
Input : 'G' // Character Output : "G" // String