Google News
logo
Java Program to convert double type variables to string
In the following example of Java program to convert a character to a string and vice-versa :
Program :
public class Main {
    public static void main(String[] args) {
        char ch = 'A'; // character
        String str = "Hello"; // string
        
        // convert char to string
        String charToString = Character.toString(ch);
        System.out.println("Character to String: " + charToString);
        
        // convert string to char
        char stringToChar = str.charAt(1);
        System.out.println("String to Character: " + stringToChar);
    }
}
Output :
Character to String: A
String to Character: e
In the above program, we define a character ch and a string str. To convert a character to a string, we use the Character.toString() method, which takes a character as a parameter and returns a string. To convert a string to a character, we use the charAt() method of the string class, which returns the character at the specified index.

Note that Character.toString() and String.charAt() methods are part of the Java Standard Library, so no additional import statements are required.