1char[] a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
2String str = new String(a);
1// java convert array of char to string
2public class CharArrayToString
3{
4 public static void main(String[] args)
5 {
6 char[] charArray = new char[]{'F','l','o','w','e','r','B','r','a','c','k','e','t','s'};
7 String str = new String(charArray);
8 System.out.println(str);
9 }
10}
1How to convert string to array
2
3import java.util.*;
4
5public class GFG {
6
7 public static void main(String args[])
8 {
9
10 String str = "GeeksForGeeks";
11
12 // Creating array and Storing the array
13 // returned by toCharArray()
14 char[] ch = str.toCharArray();
15
16 // Printing array
17 for (char c : ch) {
18 System.out.println(c);
19 }
20 }
21}
22
1
2 // Method 1: Using String object
3 char[] ch = {'g', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g'};
4 String str = new String(ch);
5 System.out.println(str);
6