Char array to string java

Hey guys!! Welcome to flower brackets blog. In this post we will learn and execute a simple program to convert char array to string java.

char array to string java

To convert a char(char[]) to a string in java we will be creating string object by passing char array name to the constructor. Here’s the java program,

Also read – convert binary number to decimal number in java

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);
   }
}

Output:

FlowerBrackets


Now we are going to see how to convert a char array to a string in java using valueof() method of String class,

public class CharArrayToStringDemo
{
   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 = String.valueOf(charArray); 
      System.out.println(str);
   }
}

Output:

FlowerBrackets

Related Posts