convert a string to char array code example

Example 1: java string to char array

String str = "example";
char[] ch = str.toCharArray();

Example 2: convert string to char array in java

String str = "example";
char[] ch = str.toCharArray();

Example 3: char array to string

String string = String.valueOf(a);

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