java array of chars from 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: char array in java

char[] JavaCharArray = new char[5];
JavaCharArray[0] = 'r';
JavaCharArray[1] = 's';
JavaCharArray[2] = 't';
JavaCharArray[3] = 'u';

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