I'm learning about stream expressions and trying to use them to construct a 2D boolean array, with all values set to true. Something like:
boolean[][] bool_array = [stream expression returning a
2D array boolean[h][w], all values set to true]
Is this possible to do and what would the expression be?
I know int[][]
arrays may be created using streams, for example
int h=5;
int w=8;
int[][] int_array = IntStream.range(0,h).mapToObj(i->IntStream.range(0,w).
map(j->1).toArray()).toArray(int[][]::new);
returns an int[5][8]
filled with ones. But trying to get this to work for boolean[][]
boolean[][] bool_array = IntStream.range(0,h).mapToObj(i->IntStream.range(0,w).
mapToObj(j->true).toArray()).toArray(boolean[][]::new);
throws an ArrayStoreException
.