How to convert char to String in Java
Example:
Input: ch='A'
Output: "A"
Approach: 1: Using toString()
Java
public class CharToString {public static void main(String[] args) {char ch = 'A';String str = charToString(ch);System.out.println("String is " + str);}private static String charToString(char ch) {return Character.toString(ch);}}
Approach : 2: Using valueOf()
Java
public class CharToString {public static void main(String[] args) {char ch = 'A';String str = charToString(ch);System.out.println("String is " + str);}private static String charToString(char ch) {return String.valueOf(ch);}}
No comments:
Post a Comment