java char[] to string code example

Example 1: convert char to string java

char c = 'a';
String s = Character.toString(c);
//s == "a"

Example 2: char array to string java

char[] a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
String str = new String(a);

Example 3: Convert char to string java

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

Example 4: java convert a string to char[]

String string =  "ABCDEF" ;
 
char[] charsFromString = string.toCharArray(); // { 'A', 'B', 'C', 'D', 'E', 'F' }

Example 5: convert char to string

char c = 'a';
String s = Character.toString(c);

Example 6: convert char[] to string

char[] chars = {'a','b','c','d','e'};
string s = new string(chars);