cstring to char array code example

Example 1: 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 2: converting char array to string

// Convert char array to String in Java
class Util
{
    public static void main(String[] args)
    {
        char[] chars = {'T', 'e', 'c', 'h', 'i', 'e', ' ', 
                        'D', 'e', 'l', 'i', 'g', 'h', 't'};
 
        String string = new String(chars);
        System.out.println(string);
    }
}