java8 stream of arrays to 2 dimensional array

后端 未结 1 707
情深已故
情深已故 2021-01-13 16:53

I\'m new to Java8 and I can\'t use streams to map one array into another 2 dimensional array.

I have one 2-dimensional array which is a pattern:

bool         


        
1条回答
  •  抹茶落季
    2021-01-13 17:45

    You can do it like so,

    boolean[][] result = Arrays.stream(keys).mapToObj(i -> pattern[i]).toArray(boolean[][]::new);
    

    Since you have Stream after the map stage, you only need to provide an array generator function.

    0 讨论(0)
提交回复
热议问题