Java Program to Convert Character to String

Object Oriented ProgrammingJava8Java Programming

The toString() method of the Character class converts the character to string. You can use this method to convert the given character to String.

Example

import java.util.Scanner;
public class CharToString {
   public static void main(String args[]){
      System.out.println("Enter a character ::");
      Scanner sc = new Scanner(System.in);
      char ch = sc.next().charAt(0);
      String str = Character.toString(ch);
      System.out.println(str);
   }
}

Output

Enter a character ::
h
h
raja
Updated on 13-Mar-2020 11:23:34

Advertisements