![]() |
VOOZH | about |
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.
Input : 'G' // Character Output : "G" // String
Let's discuss three methods in detail for Convert Char to String 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:
Char to String using Character.toString method : G
We can convert a char to a string object in Java by using String.valueOf() method of String Class.
Char to String using String.valueOf() method : G
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:
Char to String using Concatenation : G
We can convert a char to a string object in Java by using java.lang.Character class, which is a wrapper for the char primitive type.
Note: This method may arise a warning due to the new keyword as Character(char) in Character has been deprecated and marked for removal.
Below is the implementation of the above method:
Char to String using Character.toString method : G
This will help you to avoid warnings and let you use deprecated methods. This will help you remove the warnings as mentioned in Method 3
Below is the implementation of the above method:
Char to String using @Deprecated Annotation and toString method : G
We can convert a char to a string object in Java by using String.valueOf(char[]) method.
Below is the implementation of the above method:
Char to String using String.valueOf(new char[]) method : G