convert character array to string code example

Example 1: char array to string java

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

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: char array to string

String string = String.valueOf(a);

Example 4: 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);
    }
}

Example 5: how to turn a character array into a string

char [] exampleCharArray = {'a', 'b', 'c'};
string exampleString = new string(exampleCharArray);

Example 6: array of char to string in java

String x2 = "hello";
String newSortedString = "";
Object[] y = x2.toLowerCase()
                .chars()
                .sorted()
                .mapToObj(i -> (char) i)
                .toArray();

for (Object o: y) {
  newSortedString = newSortedString.concat(o.toString());
}

System.out.println(newSortedString);

Tags:

Java Example