CodesJava

Easy learning with example program codes

Char to string in java


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

package com.codesjava;
 
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.codesjava;
 
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.

Please follow and like us:
Posted in Java   


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki