to char array string java code example

Example 1: java string to char array

String str = "example";
char[] ch = str.toCharArray();

Example 2: Convert char array to string in java

// java convert array of char to string
public class CharArrayToString
{
   public static void main(String[] args)
   {
      char[] charArray = new char[]{'F','l','o','w','e','r','B','r','a','c','k','e','t','s'};
      String str = new String(charArray);
      System.out.println(str);
   }
}

Example 3: java char array to string

final char[] charArray = { 'g','e','e','k','s','f','o','r','g','e','e','k','s' };
    String string = new String(charArray);

	System.out.println(string);

	// -> "geeksforgeeks"