How To Convert Char To String and a String to char in Java |

Published: 19 May 2021
on channel: Aman Tripathi
19
4

INSTAGRAM |   / javac_programming  
Program to convert char to String
We have following two ways for char to String conversion.
Method 1: Using toString() method
Method 2: Usng valueOf() method

class CharToStringDemo
{
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


On this page of the site you can watch the video online How To Convert Char To String and a String to char in Java | with a duration of hours minute second in good quality, which was uploaded by the user Aman Tripathi 19 May 2021, share the link with friends and acquaintances, this video has already been watched 19 times on youtube and it was liked by 4 viewers. Enjoy your viewing!