I want to make a program that does calculations on different multidimensional arrays, or really just the simple task of printing it. I am hoping to have the function parameters that sort of look like
printArray(Int Array of any dimensions, int dimensions, int... sizes)
One goal for calculations is the mode, so I am thinking of flattening out all the arrays to do any calculations or modifications.
I've looked into how arrays and stream can be used to flatten out an array.
2d:
Arrays.stream(arr).flatMap(Arrays::stream).flatMapToInt(Arrays::stream).toArray();
3d:
Arrays.stream(arr).flatMap(Arrays::stream).flatMap(Arrays::stream).flatMapToInt(Arrays::stream).toArray();
but it also is not generic since every dimension it requires another ".flatMap
". And I still don't know how to make that kind of parameters that accept any dimensions.