Java Program To Convert Char To String
- June 05, 2020
- by

Java Program To Convert Char To String
In this Java Program, we convert char to string by using toString() and valueOf() methods.
Logic : Method 1: using toString() method
String str = Character.toString(ch);
Method 2: using valueOf() method
String str2 = String.valueOf(ch);
Step 1 : For method 1, create variable ch and store character a in it.
Step 2 : Use the logic of method 1 and store it in the variable str.
Step 3 : Print the result by using System.out.print method
Step 4 : For method 2, use the logic of method 2 and store it in the variable str2.
Step 5 : Print the result by using System.out.print method
Program :
public class CharToString
{
public static void main(String[] args)
{
//Method 1: using toString() method
char ch = 'a';
String str = Character.toString(ch);
System.out.println("String is:"+str);
//Method 2: using valueOf() method
String str2 = String.valueOf(ch);
System.out.println("String is:"+str2);
}
}
Output:
String is : a
String is : a
For execution of the same do visit my YouTube Channel:

0 comments:
Post a Comment