We are given an array of Strings and what we require is a char[], i.e, array of all characters in all the Strings For example:
Input: [i, love, you]
output:
In Java 8 we can use streams.
public char[] convert(String[] words) {
return Arrays.stream(words)
.collect(Collectors.joining())
.toCharArray();
}
Here we created a stream from an array using Array.stream(T[] array) where T is the type of the array elements. Than we obtain a string using Collectors.joining(). Finally we get a char array using the String's toCharArray() method.