I am trying to break a string down into substrings of size 3, and convert each substring into an array of strings, and return the final array recursively.
So far I have the following:
private static String[] substrings(String string) {
// base case
if (string.length() <= 3) return new String[] { string };
// this will return
return (Stream.concat(Arrays.stream(new String[]{string.substring(0,3)}), Arrays.stream(new String[] {string.substring(3)})).toArray(String[]::new));
}
How would you call the last function recursively and how I would merge the String substrings recursively.
Any input appreciated.