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
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: converting char array to string
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 4: how to covert array into a char
String s="Welcome to Java Programming";
char arr[]=s.toCharArray();
for(int i=0;i<arr.length;i++){
System.out.println("Data at ["+i+"]="+arr[i]);
}