I'm trying to use streams to flatten a multidimensional string array. I could do it with loops but streams seems to be the more idiomatic way. I'm aware of this question but that uses integer specific methods. The following returns an object array instead of the expected String[]
.
String[][][] sources = new String[][][]{
{{"a","b","c"},{"d","e","f"}}
{{"g","h","i"},{"j","k","l"}}
};
String[] values = Arrays.stream(sources[0])
.flatMap(Arrays::stream)
.toArray();