to char array java code example
Example 1: java string to char array
String str = "example";
char[] ch = str.toCharArray();
Example 2: char array to string java
char[] a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
String str = new String(a);
Example 3: 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 4: string to char in java
// getting single character from string..
String str="abcd";
char c=str.toChar(0);
System.out.println("output is "+c); // output is a
Example 5: convert string to char array in java
String str = "example";
char[] ch = str.toCharArray();
Example 6: char array to arraylist java
myString.chars().mapToObj(c -> (char) c).collect(Collectors.toList());