How to use Character.toString() Method In Java
We can convert a char to a string object in Java by using the Character.toString() method of Character class.
Below is the Java implementation of the above method:
Java
// Java Program to Convert Char to String // Using toString() method of Character class // 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' ; // Converting the char to String using toString // method of Character class and storing it in a // string String s = Character.toString(c); // Print and display the above string System.out.println( "Char to String using Character.toString():" + " " + s); } } |
Output
Char to String using Character.toString method : 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