Tutorialspoint examples

Learn java tutorial with examples for beginners online

Convert char to string java program


Java convert char to string using Character.toString() method

package com.tutorialspointexamples;
 
public class CharToString {
  public static void main(String args[]){
      char ch = 'a';
      //Convert char to string
      String str = Character.toString(ch);
      System.out.println("String is: "+str);
  }
}

Output:

String is: a

Download this example.

Java convert char to string using String.valueOf() method

package com.tutorialspointexamples;
 
public class CharToString {
  public static void main(String args[]){
      char ch = 'a';
      //Convert char to string
      String str = String.valueOf(ch);
      System.out.println("String is: "+str);
  }
}

Output:

String is: a

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status