![]() |
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.
Example of Conversion of Char to String JavaInput : 'G' // Character Output : "G" // String Methods to Convert Char to StringLet’s discuss three methods in detail for Convert Char to String in Java: 1. Using Character.toString() MethodWe 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
Output
Char to String using Character.toString method : G 2. Using valueOf() methodWe can convert a char to a string object in Java by using String.valueOf() method of String Class. Below is the java implementation of the above method:Java
Output
Char to String using String.valueOf() method : G 3. Java char to String Example: Using Concatenation of StringsWe 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
Output
Char to String using Concatenation : G Java char to String: Other Examplesa) Using Character Wrapper Class for Char to String ConversionWe 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.
Below is the implementation of the above method: Java
Output
Char to String using Character.toString method : G Output:![]() Command Prompt b) Using @deprecated annotation with Character.toString().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: Java
Output
Char to String using @Deprecated Annotation and toString method : G c) Using the String.valueOf() method of the String classWe can convert a char to a string object in Java by using String.valueOf(char[]) method. Below is the implementation of the above method: Java
Output
Char to String using String.valueOf(new char[]) method : G |
Reffered: https://www.geeksforgeeks.org
Java |
Related |
---|
|
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |